Hi Nathan,
attached is a Nuke script that contains a group node with a python button
and a sticky-note that contains the Python script. Just save it in your
Nuke path.
This seems to work a little bit better than my full script, but it still
crashes a lot. It crashes for example if I set it above 10 and also often
when I set it back to 1. In my full script I have a couple of more loops
that does other things (set inputs, moves node around to x,y pos). I'm
pretty new to Python so I would very much appreciate a nod in the right
direction on this (the only reason I got this far is because of this list).
Thanks.
#! C:/Program Files/Nuke6.3v2/Nuke6.3.exe -nx
version 6.3 v2
define_window_layout_xml {<?xml version="1.0" encoding="UTF-8"?>
<layout version="1.0">
<window x="0" y="22" w="1680" h="1024" screen="0">
<splitter orientation="1">
<split size="1052"/>
<splitter orientation="1">
<split size="40"/>
<dock id="" hideTitles="1" activePageId="Toolbar.1">
<page id="Toolbar.1"/>
</dock>
<split size="1008"/>
<splitter orientation="2">
<split size="480"/>
<dock id="" activePageId="Viewer.1">
<page id="Viewer.1"/>
</dock>
<split size="479"/>
<dock id="" activePageId="DAG.1">
<page id="DAG.1"/>
<page id="Curve Editor.1"/>
<page id="DopeSheet.1"/>
</dock>
</splitter>
</splitter>
<split size="608"/>
<dock id="" activePageId="Properties.1">
<page id="Properties.1"/>
<page id="Script Editor.1"/>
</dock>
</splitter>
</window>
</layout>
}
Root {
inputs 0
name C:/Users/Simon/Desktop/to_nuke_list.nk
fps 25
format "1920 1080 0 0 1920 1080 1 HD"
proxy_type scale
proxy_format "1024 778 0 0 1024 778 1 1K_Super_35(full-ap)"
}
StickyNote {
inputs 0
name StickyNote1
label "from __future__ import with_statement\nimport os\nimport
nuke\nimport nukescripts\nimport re\n\ndef test():\n\n n =
nuke.thisNode()\n blur_name = \"sg_blur\"\n merge_name =
\"sg_merge\"\n blur_reg = re.compile(blur_name)\n merge_reg =
re.compile(merge_name)\n\n # Delete knobs\n for b in n.knobs():\n
if blur_reg.match(b) or merge_reg.match(b):\n
n\[b].setValue(0)\n nuke.message( str(n\[b].value()) )\n
n.removeKnob(n.knobs()\[b])\n\n # Access nodes inside group:\n
with n:\n\n # Delete old nodes.\n for a in
nuke.allNodes():\n old_name = a\[\"name\"].value()\n
if blur_reg.match(old_name) or merge_reg.match(old_name):\n
if a.Class() == \"Merge2\" or a.Class() == \"Blur\":\n
nuke.delete(a)\n\n # Set up values.\n num =
n\[\"number\"].value()\n\n for i in range(num):\n\n #
Create blur\n b = nuke.createNode(\"Blur\")\n
b\[\"name\"].setValue(blur_name + str(i + 100)) \n\n # Create
blur knobs\n k = nuke.Link_Knob( blur_name + str(i + 1) )\n
k.makeLink(str(b\[\"name\"].value()), \"size\" )\n
k.setLabel( \"blur\" + str(i + 1) )\n n.addKnob(k)\n\n
#Create merge node.\n m = nuke.createNode(\"Merge2\")\n
m\[\"name\"].setValue(merge_name + str(i + 100))\n\n #
Create merge knobs\n e = nuke.Link_Knob( merge_name + str(i + 1)
)\n e.makeLink(str(m\[\"name\"].value()), \"mix\" )\n
e.setLabel( \"merge\" + str(i + 1) )\n n.addKnob(e)\n
"
xpos 216
ypos -253
}
Group {
inputs 0
name Group1
xpos -32
ypos 7
addUserKnob {20 User}
addUserKnob {3 number l "number of loops"}
number 3
addUserKnob {22 run_script l "run script" T "import
to_nuke_list\n\nto_nuke_list.test()" +STARTLINE}
}
Input {
inputs 0
name Input1
xpos 132
ypos -89
}
NoOp {
name NoOp1
xpos 132
ypos -49
}
Output {
name Output1
xpos 132
ypos 51
}
Blur {
inputs 0
name sg_blur100
}
push 0
Merge2 {
inputs 2
name sg_merge100
}
Blur {
name sg_blur101
}
push 0
Merge2 {
inputs 2
name sg_merge101
}
Blur {
name sg_blur102
}
push 0
Merge2 {
inputs 2
name sg_merge102
selected true
}
end_group
Viewer {
frame 1
viewerProcess rec709
input_process false
name Viewer1
xpos -107
ypos 430
}
StickyNote {
inputs 0
name StickyNote2
label "Save this script in your Nuke-path. Name: to_nuke_list.py"
note_font_size 21
xpos 128
ypos -327
}
2012/5/1 Nathan Rusch <[email protected]>
> I can’t reproduce your crash with the code you have provided, even when
> the knob count is upped to 50. Can you provide any more of the code that is
> running from the button?
>
> -Nathan
>
>
> *From:* Simon Björk <[email protected]>
> *Sent:* Tuesday, May 01, 2012 1:38 PM
> *To:* [email protected]
> *Subject:* [Nuke-python] Re: Adding/Removing knobs and crashing
>
> I've searched the archives and I've found that resetting the value of a
> knob before removing it helps. Also, adding a nuke.message("blabla") in the
> loop helps as well. It's almost like Nuke doesn't keep up with the python
> script.
>
> I should add that my full script creates two nodes within the group for
> each loop, and then add two link_Knobs to the main group node. Currently
> (with the above cheats), it works with 1 to around 6 loops, but if I go
> bigger, Nuke crashes.
>
> Any ideas?
>
>
> 2012/5/1 Simon Björk <[email protected]>
>
>> Hi all,
>>
>> I've got a little group-node with a python button that adds nodes within
>> the group and expose certain values via Link-knobs. It seems to work but
>> often it causes Nuke to crash, especially if I run the script with high
>> number of loops (above 10), and also setting it back to 1.
>>
>> I've attached some code that you can run on a node. It's very likely that
>> I'm doing something wrong here, but I can't seem to find it myself. Just
>> adjust the num variable to create different numbers of sliders.
>>
>>
>> import re
>>
>>
>>
>> n = nuke.selectedNode()
>>
>> name = "tester"
>>
>> reg = re.compile(name)
>>
>> num = 10
>>
>>
>>
>> for b in n.knobs():
>>
>> if reg.match(b):
>>
>> n.removeKnob(n.knobs()[b])
>>
>>
>>
>> for i in range(num):
>>
>> k = nuke.Link_Knob( name + str(i + 1) )
>>
>> n.addKnob(k)
>>
>>
>>
>> Thanks.
>>
>> --
>> --------------------------------
>> Stiller Studios
>> Lidingö/Sweden
>>
>> Simon Björk
>> Stiller Studios
>> +46 (0)8 555 23 560
>> Ekholmsnäsvägen 40, S-181 41 Lidingö
>> [email protected]
>> www.stillerstudios.se
>>
>> find us:
>> http://www.eniro.se/query?search_word=stiller+studios&geo_area=liding%F6&what=all
>>
>>
>>
>
>
> --
> --------------------------------
> Stiller Studios
> Lidingö/Sweden
>
> Simon Björk
> Stiller Studios
> +46 (0)8 555 23 560
> Ekholmsnäsvägen 40, S-181 41 Lidingö
> [email protected]
> www.stillerstudios.se
>
> find us:
> http://www.eniro.se/query?search_word=stiller+studios&geo_area=liding%F6&what=all
>
>
> ------------------------------
> _______________________________________________
> Nuke-python mailing list
> [email protected], http://forums.thefoundry.co.uk/
> http://support.thefoundry.co.uk/cgi-bin/mailman/listinfo/nuke-python
>
>
> _______________________________________________
> Nuke-python mailing list
> [email protected], http://forums.thefoundry.co.uk/
> http://support.thefoundry.co.uk/cgi-bin/mailman/listinfo/nuke-python
>
>
--
--------------------------------
Stiller Studios
Lidingö/Sweden
Simon Björk
Stiller Studios
+46 (0)8 555 23 560
Ekholmsnäsvägen 40, S-181 41 Lidingö
[email protected]
www.stillerstudios.se
find us:
http://www.eniro.se/query?search_word=stiller+studios&geo_area=liding%F6&what=all
_______________________________________________
Nuke-python mailing list
[email protected], http://forums.thefoundry.co.uk/
http://support.thefoundry.co.uk/cgi-bin/mailman/listinfo/nuke-python