Thanks for taking a look at it Nathan, I will see if I can give it a try in a newer version. Thanks for the code clean-up as well, great help.
2012/5/2 Nathan Rusch <[email protected]> > Hmm, I still can’t get it to crash... > > Is there any way you can try this with the latest version of Nuke to see > if it’s possibly related to a past bug? > > As far as your code goes, it works fine. The only changes I would be sure > to make (without getting too picky) are some order-of-operations things and > some re-use of variables. > > > from __future__ import with_statement > import re > import nuke > > blurPrefix = 'sg_blur' > mergePrefix = 'sg_merge' > nameRE = re.compile('^(%s|%s)' % (blurPrefix, mergePrefix)) > > def test(): > tn = nuke.thisNode() > > for name, knob in tn.knobs().iteritems(): > if nameRE.search(name): > tn.removeKnob(knob) > > with tn: > for a in nuke.allNodes('Blur') + nuke.allNodes('Merge2'): > if nameRE.search(a.name()): > nuke.delete(a) > > for i in range(1, tn['number'].value() + 1): > blurName = '%s%d' % (blurPrefix, i + 100) > nuke.createNode('Blur', 'name %s' % blurName, inpanel=False) > > k = nuke.Link_Knob('%s%d' % (blurPrefix, i), 'blur %d' % i) > k.makeLink(blurName, 'size') > tn.addKnob(k) > > mergeName = '%s%d' % (mergePrefix, i + 100) > nuke.createNode("Merge2", 'name %s' % mergeName, inpanel=False) > > k = nuke.Link_Knob('%s%d' % (mergePrefix, i), 'merge %d' % i) > k.makeLink(mergeName, 'mix') > tn.addKnob(k) > > > -Nathan > > > *From:* Simon Björk <[email protected]> > *Sent:* Wednesday, May 02, 2012 1:08 PM > *To:* Nuke Python discussion <[email protected]> > *Subject:* Re: [Nuke-python] Re: Adding/Removing knobs and crashing > > 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 > } > > > _______________________________________________ > 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
