Python

Multiplatform dynamic font path

Every time we create a group or a gizmo, or even when we simply save our script that uses a Text node, we know that the font path inside the Text node remains baked, fixed. That is not a problem if you are keeping that tool for yourself in your own computer.…

Regular Expressions (re module) to Fix Broken Scripts

I will state up front I am no expert in regular expressions, but by a lot of pounding and testing, I've gotten some really useful results for painlessly helping out with broken scripts (skip tutorials and go to recipes...). For a primer on regular expressions go here.…

List of Nuke Flags

""" flags.py nuke flags for easy access from /include/DDImage/Knob.h These are updated for nuke 6.2 with added comments. Flags not in 6.1 are READ_ONLY, GRANULARY_UNDO, NO_RECURSIVE_PATHS comments taken from Documentation/NDK/Plugins/namespaceDD_1_1Image.html#426fa024992892aa333e53b4e19109b5 """ # General flags (must not intersect any class-specific flags): # Values that work for any knob: DISABLED            = 0x00000080    # DISABLED Set by disable(), cleared by enable().…

Creating a new menu for Custom Gizmos

I had TONS of trouble trying to figure out how to make a menu, so here is my tutorial. (Keep in mind, this is a tutorial for super ultra mega beginners) Be SURE you read the directories carefully during this tutorial! What we will do: We will add a new menu to your "Nodes" menu.…

Verbose to super verbose python Trace Debugging

Sometimes, verbose just isn't enough. There are a couple options: 1st level: In your nuke home dir (assuming you haven't changed it, ~/.nuke on OSX and Linux - I don't know Windows), add or modify the init.py file by adding the line: import callbacksTrace This prints out every callback nuke makes.…

Some Flags

Using flags can be frustrating because not all flags are easily accessed or documented. Create a flags.py file and you have a simple way to easily get at them. Thanks to Nathan and Dee for the tip on where to find them.…

Using nuke.animation without tearing your hair out

This is quite possibly the most stubborn Nuke Python function I've ever encountered, and it took me a lot of poking and prodding to get it worked out, so I figured I should spread the knowledge around. nuke.animation is the Python equivalent of (/wrapper for?) the TCL "animation" command.…

Getting correct format and frame range if QuickTime movie, added via Python

If you want to add a QuickTime movie to the DAG pythonically, here's a trick for making sure you get the correct format and frame range. (setValue on the file knob after a node has been created does not work as expected) filepath = myMov.mov nuke.createNode("Read", "file {"+filePath+"}")

Tech-artists.org - Python External Recipes

Some very useful information and some recipes:   http://tech-artists.org/wiki/Portal:Python

Hotkey for toggling Depth in Viewer

Here is an example of how to add a hotkey to toggle the viewer' layer (aka channel set) to depth and back.…

Checking if a Node is a Gizmo

There are several ways to find if a certain node is a gizmo or not in Nuke. Here is a list of the most common ways to achieve that and their respective pitfalls if any.…

Random Frames from Read node

If you want to generate random frames from your current read node : Pace a FrameHold node below your read node Then goto first frame:- edit expression and place this code int( random(frame) * (last_frame-first_frame+1) + first_frame ) )

AnimationCurve and AnimationKey objects

AnimationCurve Objects AnimationCurve objects contain the animation data of a given animated knob, and can be accessed using a knob’s .animation() or .animations() methods. NOTE: AnimationCurves can be created manually using Python, but for the purposes of this article, we will assume they all come from pre-animated knobs.…

Notes for PythonForArtists_PythonPanel_UI - video tutorial

PythonForArtists_PythonPanels_UI (legacy) - Frank Rueter click here for video import re class SearchReplacePanel( nukescripts.PythonPanel ): def __init__( self ): nukescripts.PythonPanel.__init__( self, 'Search and Replace', 'com.ohufx.SearchReplace')   # CREATE KNOBS self.nodesChoice = nuke.Enumeration_Knob( 'nodes', 'Source Nodes', ['all', 'selected']) self.searchStr = nuke.String_Knob('searchStr', 'Search for:') self.update = nuke.PyScript_Knob('update', 'Update') self.info = nuke.Multiline_Eval_String_Knob('info', 'Found') self.info.setEnabled( False ) self.replaceStr = nuke.String_Knob('replaceStr', 'Replace with:') self.replace =…

Knob Animation and Python: A Primer

Interact with animated knobs and animated curves using Python.

Notes for PythonForArtists - SimpleUserInterfaces (legacy) - video tutorial

PythonForArtists_SimpleUserIntervaces (legacy) - Frank Rueter click here for video Nuke has pretty simple python commands that let you create simple user interfaces - without having to dive too much into python panels.…

code.activestate.com - Python External Recipes

This is a great source for python snippets: http://code.activestate.com/recipes/langs/python/

Setting Context to Node, Knob or Curve Object

I often need to run code from within a group or gizmo instead of the top level (so nuke.allNodes() would return all nodes in a group rather than the top level for instance).…

Getting the Index Context of a Knob

Scope: There seems to be no Knob python method to get the context of a specific index inside a knob with multiple values (like an XYZ_Knob). nuke.thisKnob()  would get you the knob something is executed from, but not the index within the knob.…

TransformThis - example for Smart Node Creation

Here is  simple recipe for your menu.py, to make a hotkey that creates a normal Transform node for 2D nodes (just like th default 't' does), but if a 3D node is selected, it will create a TransformGeo node instead: To find out if the selected node is a 3D node, I usually just check for a knob that 2D…