Notice: Function _load_textdomain_just_in_time was called incorrectly. Translation loading for the cycloneslider domain was triggered too early. This is usually an indicator for some code in the plugin or theme running too early. Translations should be loaded at the init action or later. Please see Debugging in WordPress for more information. (This message was added in version 6.7.0.) in /home2/wacggq0abkde/public_html/wp-includes/functions.php on line 6114

Notice: Function _load_textdomain_just_in_time was called incorrectly. Translation loading for the cartel domain was triggered too early. This is usually an indicator for some code in the plugin or theme running too early. Translations should be loaded at the init action or later. Please see Debugging in WordPress for more information. (This message was added in version 6.7.0.) in /home2/wacggq0abkde/public_html/wp-includes/functions.php on line 6114

Warning: Cannot modify header information - headers already sent by (output started at /home2/wacggq0abkde/public_html/wp-includes/functions.php:6114) in /home2/wacggq0abkde/public_html/wp-includes/rest-api/class-wp-rest-server.php on line 1893

Warning: Cannot modify header information - headers already sent by (output started at /home2/wacggq0abkde/public_html/wp-includes/functions.php:6114) in /home2/wacggq0abkde/public_html/wp-includes/rest-api/class-wp-rest-server.php on line 1893

Warning: Cannot modify header information - headers already sent by (output started at /home2/wacggq0abkde/public_html/wp-includes/functions.php:6114) in /home2/wacggq0abkde/public_html/wp-includes/rest-api/class-wp-rest-server.php on line 1893

Warning: Cannot modify header information - headers already sent by (output started at /home2/wacggq0abkde/public_html/wp-includes/functions.php:6114) in /home2/wacggq0abkde/public_html/wp-includes/rest-api/class-wp-rest-server.php on line 1893

Warning: Cannot modify header information - headers already sent by (output started at /home2/wacggq0abkde/public_html/wp-includes/functions.php:6114) in /home2/wacggq0abkde/public_html/wp-includes/rest-api/class-wp-rest-server.php on line 1893

Warning: Cannot modify header information - headers already sent by (output started at /home2/wacggq0abkde/public_html/wp-includes/functions.php:6114) in /home2/wacggq0abkde/public_html/wp-includes/rest-api/class-wp-rest-server.php on line 1893

Warning: Cannot modify header information - headers already sent by (output started at /home2/wacggq0abkde/public_html/wp-includes/functions.php:6114) in /home2/wacggq0abkde/public_html/wp-includes/rest-api/class-wp-rest-server.php on line 1893

Warning: Cannot modify header information - headers already sent by (output started at /home2/wacggq0abkde/public_html/wp-includes/functions.php:6114) in /home2/wacggq0abkde/public_html/wp-includes/rest-api/class-wp-rest-server.php on line 1893
{"id":1921,"date":"2016-06-01T15:15:12","date_gmt":"2016-06-01T14:15:12","guid":{"rendered":"http:\/\/boris-mc.com\/?p=1921"},"modified":"2019-04-25T17:23:44","modified_gmt":"2019-04-25T16:23:44","slug":"3-simple-python-snippets-that-will-make-your-life-a-bit-easier","status":"publish","type":"post","link":"https:\/\/boris-mc.com\/?p=1921","title":{"rendered":"3 SIMPLE PYTHON SCRIPTS THAT’LL MAKE YOUR COMPING A TINY BIT EASIER"},"content":{"rendered":"
\n
\n

tl;dr: <\/strong>some usefull Python snippets for Nuke.<\/p>\n<\/div><\/div>\n

\n
So I’m\u00a0finally applying some\u00a0Python knowledge I’ve been\u00a0learning lately to actually usefull stuff. Cool!! I will celebrate it by sharing some very, super simple Python snippets that will enable you to work (slightly) faster within\u00a0Nuke.<\/div>\n
<\/div>\n
Disclaimer<\/strong>:\u00a0I’m fairly new to Python so you can expect finding not very elegant, unpythonic code. Sorry for that!<\/div>\n<\/div><\/div>\n<\/div>\n
<\/div>\n
\n
\n
snippet #1<\/strong><\/h6>\n<\/div><\/div>\n
\n
This tiny piece of code enables you to automatically create a new ReadNode<\/strong> reading the filepath from a selected\u00a0WriteNode.\u00a0<\/strong>Mapping this code to a hotkey makes it a really handy action to use. So let’s see the actual code:<\/div>\n
<\/div>\n
\u00a0
.__author__ Boris Martinez\r\n\r\nimport nuke, re, math, os\r\n\r\ndef AutoReadFromWrite():\r\n\r\n    try:\r\n        n = nuke.selectedNode()\r\n\t\t\r\n    except:\r\n    \r\n        m = nuke.message('select a WriteNode,dude')\r\n        m.show()\r\n\telse:\r\n\t\tif n.Class() == 'Write':\r\n\t\t\t#fetching data from the write node\r\n            p = n.knob('file').getValue()\r\n\t\t\tfstf = n.knob('first').getValue()\r\n\t\t\tlstf = n;knob('last').getValue()\r\n\t\t\tcolorspace = str(i.knob('colorspace').getValue()\r\n\t\t\t#fetching data from the write node\r\n            r = nuke.createNode('Read')\r\n            r.knob('file').setValue(p)\r\n\t\t\tr.knob('first').setValue(int(firstFrame))\r\n\t\t\tr.knob('last').setValue(int(lastFrame))\r\n\t\t\tr.knob('origfirst').setValue(int(firstFrame))\r\n\t\t\tr.knob('origlast').setValue(int(lastFrame))\r\n\t\t\tr.knob('colorspace').setValue(colorspace)\r\n\t\telse:\r\n\t\t\tm = nuke.message("Select a Write node, dude!")\r\n\t\t\r\n\t\t\r\n AutoReadFromWrite()\r\n<\/pre><\/div><\/div>\n<\/div><\/div>\n<\/div>\n
\n
\n
snippet #2<\/strong><\/h6>\n<\/div><\/div>\n
\n
This ones takes advantage of some of the concepts from the AutoReadFromWrite<\/strong> <\/span>function to\u00a0enable the user to open in the explorer the folder that\u00a0the filepath knob of a selected ReadNode<\/strong> is pointing to.\u00a0<\/span><\/div>\n
<\/div>\n
\u00a0
.__author__ Boris Martinez\r\n\r\nimport nuke,os\r\n\r\ndef AutoExploreFromRead():\r\n    \r\n    try:\r\n        n = nuke.selectedNode()\r\n        f = n.knob("file").getValue()\r\n        p = os.path.dirname(f)\r\n        print "path is %s" %p\r\n        os.startfile(p)\r\n    except:\r\n        p = nuke.message("no file selected")\r\n        p.show()\r\n        print "no file selected"\r\n\r\nAutoExploreFromRead()<\/pre><\/div><\/div>\n
<\/div>\n<\/div><\/div>\n<\/div>\n
\n
\n
snippet #3<\/strong><\/h6>\n<\/div><\/div>\n
\n
\n
Here we have a little trickier code comprising concepts\u00a0we did not see in the previous ones. Stuff like iterations<\/strong>, classes<\/strong> and GUI<\/strong> creation. Functionality wise, it’s really simple! What it does is just creating a randomized animation curve in selected lights. Useful if you\u00a0want to create some randomized animation for lights in the scene (it affects specifically the intensity value of selected lights).<\/div>\n<\/div>\n
<\/div>\n
\u00a0
.__author__ Boris Martinez\r\n\r\nimport nuke\r\nimport random\r\nimport nukescripts\r\n\r\n\r\ndef lightRandomizer(m,i,o):\r\n    try:\r\n        nodes = nuke.selectedNodes()\r\n        variation = None\r\n        for light in nodes:\r\n            for e in range(i,o):\r\n                variation = random.randrange(1,5)\r\n                if light.Class() == "Light2":\r\n\r\n                    light['intensity'].setAnimated()\r\n                    light['intensity'].setValueAt(variation * m,e)\r\n    except:\r\n        ep = nuke.message("No nodes selected")\r\n        ep.show()\r\n\r\ndef lightRandExpression():\r\n    nodes = nuke.selectedNodes()\r\n    variation = None\r\n    for light in nodes:\r\n        variation = random.randrange(1,5)\r\n        if light.Class() == "Light2":\r\n            light['intensity'].setExpression("random(frame)")\r\n            light['intensity'].setAnimated()\r\n\r\n#creating the panel for introducing a multiplicator and launching the lightRandomizer function\r\n\r\nclass modalPanel(nukescripts.PythonPanel):\r\n\r\n    def __init__(self):\r\n        nukescripts.PythonPanel.__init__(self,"multiplier")\r\n        self.m = nuke.Double_Knob("intensity multiplier", "intensity multiplier: ")\r\n        self.addKnob( self.m )\r\n        self.fRange = nuke.String_Knob('fRange', 'Animation Range', '%s-%s' % (nuke.root().firstFrame(), nuke.root().lastFrame()))\r\n        self.addKnob(self.fRange)\r\n\r\n    def showModalDialog( self ):\r\n        nukescripts.PythonPanel.showModalDialog(self)\r\n\r\n    def giveMultValue(self):\r\n        return  self.m.getValue()\r\n\r\n    def giveFrameRangeValue(self):\r\n        return self.fRange.getValue()\r\n\r\n#wrapper function\r\n\r\ndef lightRandmWrapper():\r\n    panel = modalPanel() # an instance from the modalPanel Class\r\n    show = panel.showModalDialog()\r\n    multiplier = panel.giveMultValue()\r\n    frameRange = panel.giveFrameRangeValue()\r\n    frameRangeSplitted = frameRange.split("-")\r\n    ini = int(frameRangeSplitted[0])\r\n    fin = int(frameRangeSplitted[-1])\r\n\r\n    #print "frameRange is: ", frameRange\r\n    #print type(frameRange)\r\n\r\n    lightRandomizer(multiplier,ini,fin)\r\n    #p = nuke.message (" Boris says: lights randomized, cool!")\r\n    #p.show()\r\n\r\nlightRandmWrapper()\r\n#lightRandExpression\r\n\r\n<\/pre><\/div><\/div>\n<\/div><\/div>\n<\/div>\n
<\/div>\n
So, for the time being, this is all folks. Feel free to copy this snippets for your personal use in Nuke.\u00a0For snippets #1 & #2 I highly recommend mapping them to a hotkey. If you don’t know how to do so, checking Fxphd’s “Python for Nuke & Gizmology”<\/strong><\/a> course by Victor Perez would be really helpfull. For other general Python questions, I strongly recommend Mark Lutz’s “Programming Python”<\/strong> book.<\/div>\n
\u00a0<\/strong><\/h6>\n","protected":false},"excerpt":{"rendered":"

So, for the time being, this is all folks. Feel free to copy this snippets for your personal use in Nuke.\u00a0For snippets #1 & #2 I highly recommend mapping them to a hotkey. If you don’t know how to do so, checking Fxphd’s “Python for Nuke & Gizmology” course by Victor Perez would be really […]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[47,48,49],"tags":[51],"class_list":["post-1921","post","type-post","status-publish","format-standard","hentry","category-nuke","category-python","category-scripting","tag-python"],"_links":{"self":[{"href":"https:\/\/boris-mc.com\/index.php?rest_route=\/wp\/v2\/posts\/1921","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/boris-mc.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/boris-mc.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/boris-mc.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/boris-mc.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1921"}],"version-history":[{"count":53,"href":"https:\/\/boris-mc.com\/index.php?rest_route=\/wp\/v2\/posts\/1921\/revisions"}],"predecessor-version":[{"id":2494,"href":"https:\/\/boris-mc.com\/index.php?rest_route=\/wp\/v2\/posts\/1921\/revisions\/2494"}],"wp:attachment":[{"href":"https:\/\/boris-mc.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1921"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/boris-mc.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1921"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/boris-mc.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1921"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}