Using Python with Graph Scope Variables

Editing Variable Values

You can edit Variable values using Python rather than the Variables tab.

In this case, the value of the GsvKnob can be set and retrieved using the regular ‘setValue’ and ‘value’ functions, using a regular Python dictionary type:

For example:

rootGsvKnob = nuke.root()['gsv']
myValue = {'Custom': {'shot': 'sh001'}, '__default__': {'show': 'hot-chocolate'}}
rootGsvKnob.setValue(myValue)
print(rootGsvKnob.value())
# Result: {'Custom': {'shot': 'sh001'}, '__default__': {'show': 'hot-chocolate'}}

Python Callbacks

Python code can now be triggered when Variables are added, removed, renamed, and changed in Value.

This enables you to create custom behavior based on these events, such as creating templates of Variables, populating Variables into specific folder structures, and adding password protection for Variable value changes.

The system provides granular control by offering before and after callbacks for each operation (Add, Remove, Rename or Change in Value). This distinction is key for implementing pipeline rules:

Before Operations (addBeforeUser*): Callbacks that execute before an operation (such as adding or removing a GSV) can return False to abort or prevent the operation. This is essential for enforcing naming conventions or preventing the removal of crucial variables.

After Operations (addAfterUser*): Callbacks that execute after an operation are used for notifications, logging changes, or initiating synchronization with external systems, but they cannot prevent the operation.

Available GSV Callback Functions

Nuke provides the following functions, categorized by the action and the scope (individual GSV or GSV set):

Action

Individual GSVs

GSV Sets

Description & Notes

Add addBeforeUserAddGsv() addBeforeUserAddGsvSet()

Called before adding a GSV or GSV set. Can abort the operation by returning

False.

  addAfterUserAddGsv() addAfterUserAddGsvSet() Called after a GSV or GSV set is added.
Remove addBeforeUserRemoveGsv() addBeforeUserRemoveGsvSet()

Called before removing a GSV or GSV set. Can prevent removal by returning

False.

  addAfterUserRemoveGsv() addAfterUserRemoveGsvSet() Called after a GSV or GSV set is removed.
Rename addBeforeUserRenameGsv() addBeforeUserRenameGsvSet()

Called before renaming a GSV or GSV set. Can abort the operation by returning

False.

  addAfterUserRenameGsv() addAfterUserRenameGsvSet() Called after a GSV or GSV set is renamed.
Value Change addBeforeUserSetGsvValue  

Called before a variable's value is changed. Can abort the operation by returning

False.

  addAfterUserSetGsvValue   Called after a variable's value is changed.

Note:  For unregistering Python Callbacks, there are nuke.remove... functions for each of the registration functions above.

Note:  See more in the Nuke Developer Guide.

Note:  Variable Value Change Callbacks are missing from the List of callbacks in the Nuke Developer Guide in the Beta 4, however they are available in the build.