November 2016


tl;dr:A useful tweak to the “FrameHold” node that set by default its “frame” knob to the current frame in the timeline.

By the time I´m writing this, probably everyone has its own version of such a simple, yet day-to-day usefull tweak of a tool. Nonetheless, a couple of weeks ago a college of mine asked me to modify the “FrameHold” node so that, whenever we create one, it gets its “first_frame” knob automatically set to the frame in the timeline it is created. This imply some people could still benefit from reading this :)
My implementation of such a thing consists of a mini function that is passed to an “addOnUserCreate” callback as callable argument whenever a “FrameHold” node is created.

important: make sure to copy this code somewhere in your file to make it work. Enjoy!

.__autor__ Boris Martinez 

# function to be passed later on to a addOnUserCreate callback.
def frame_hold_to_frame():
    node = nuke.thisNode()
    curr_frame = nuke.frame()
    frame = node['first_frame'].setValue(curr_frame)
	return curr_frame
# addOnUserCreate callback.
nuke.addOnUserCreate(frame_hold_to_frame,nodeClass ="FrameHold")
Read more →


tl;dr: A useful custom knob that enables the user to to place objects in 3D while working in screen space.

I called “SmartPost” to a custom knob that enables the user to color-pick positional values from a World Point Position Pass (WPP) and then use those values to drive the XYZ coordinates of a XYZ_Knob existing it tools such as the Axis, the TransformGeo, the Sphere, the Card or the Cube node. By doing so, basically one is able to position geometry, cards, axis and such in worldspace based on color values.
This knob can therefore come in handy when working in animation projects (where the WPP is typically rendered by default), allowing us to place objects in 3D while working in screen space, ultimately saving a great deal of time and guessing work.

important:  make sure to copy this code somewhere in your file to make it work.

.__author__ Boris Martinez

# assign nuke.createNode() function to a variable for later use.
nuke_create_node = nuke.createNode

def create_my_nodes(node, knobs = "", inpanel = True):
    this function calls nuke_create_node and add a tab and a color picker knob based on the class
    of the node created.
    @param node: Node class.
    @param knobs: Optional string containing a TCL list of name value pairs (like "size 50 quality 19")
    @param inpanel:  Optional boolean to open the control bin (default is True; only applies when the GUI is running).
    @return: result
    result = nuke_create_node(node, knobs, inpanel) # call to nuke_create_node

    if node == "Sphere" or node == "TransformGeo" or node == "Cube" or node == "Card2" or node == "Cylinder" or node \
            == "Axis2":
        tab = nuke.Tab_Knob('SmartPos', 'SmartPos')
        col = nuke.Color_Knob('PickPos')

    return result

# overwrite nuke.createNode
nuke.createNode = create_my_nodes

# KnobChanged callable function

def smart_post_expression():
    This is the function to be called as the first argument for the AddKnobChanged callback later on.
    Sets its context to nuke.thisNode() and picks up the changing knob by the nuke.thisKnob() command.
    @return: None
    n = nuke.thisNode()
    k = nuke.thisKnob()
    if == "PickPos":
        n['translate'].setExpression('PickPos.r', 0)
        n['translate'].setExpression('PickPos.g', 1)
        n['translate'].setExpression('PickPos.b', 2)
    return None

# adding callbacks to certain node classes.

nuke.addKnobChanged(smart_post_expression, nodeClass="TransformGeo")
nuke.addKnobChanged(smart_post_expression, nodeClass="Sphere")
nuke.addKnobChanged(smart_post_expression, nodeClass="Cube")
nuke.addKnobChanged(smart_post_expression, nodeClass="Card2")
nuke.addKnobChanged(smart_post_expression, nodeClass="Cylinder")
nuke.addKnobChanged(smart_post_expression, nodeClass="Axis2")


As a side note, I´d like to note that I don´t think it´s ideal the fact that the new “SmartPos” tab created appears first in the properties bin whenever we create a node that´s intended to have it. I´d like to see the main tab first, but so far I didn´t find the way. Any suggestion would be much appreciated. Thanks for reading!
Read more →