pythonnuke

How to create global Motion Blur parameters and control them globally?


I'd like to create a global parameters in The Foundry Nuke UI to control a motion blur value and shutter's angle.

How to accomplish this by using Python?

Any help appreciated.


Solution

  • I have found quite simple and effective method to globally control MotionBlur in Nuke – just using usual NoOp node, serving as controller, and LinkerScript. Here's how it works in practice. Create, for testing, three Transform nodes (every Transform node contains motionblur, shutter and shutter offset knobs).

    Run the LinkerScript internally in NUKE's Script Editor or externally via menu.py file. Then select all the Transform nodes and from NUKE's toolbar choose: GizmosNoOp Controls Linker. That's all. Now you can globally control MotionBlur for all the Transform nodes via NoOp controller (motionblur and shutter properties are now linked through expressions).

    Here's my LinkerScript:

    import nuke
    
    controller = nuke.nodes.NoOp() 
    # There are two identical parameters in parentheses : 
    # the 1st one is a real property's name, and the 2nd one is a label for GUI.
    knobMB = nuke.Double_Knob('motionblur', 'motionblur')
    knobSH = nuke.Double_Knob('shutter', 'shutter')
    controller.addKnob(knobMB)
    controller.addKnob(knobSH)
    
    def linkNoOpControls():
        for everyNode in nuke.selectedNodes():
            everyNode['motionblur'].setExpression('NoOp1.motionblur')
            everyNode['shutter'].setExpression('NoOp1.shutter')
    
    toolbar = nuke.menu("Nodes")
    gizmos = toolbar.addMenu("Gizmos", icon='LinkerIcon.png')
    gizmos.addCommand("NoOp Controls Linker", 'linkNoOpControls()')
    

    You should load a 24x24 pixels PNG icon file for your new command in the toolbar.

    enter image description here enter image description here

    P.S. Don't forget to drop your PNG icon file into a hidden .nuke directory (if you use a Mac, as you said, its path is – /Users/<userName>/.nuke), and adjust your menu.py file accordingly (paste the necessary Python code).

    For more details read a Nuke Directory Locations article.