SUMMARY
Launching Katana with global Graph State Variables set predefines accessible information about the context of the Katana project, which can then be accessed by the node graph or custom tools. Likewise, artists can have the predefined variables set such as file paths to shows or project folders. This article will guide the steps on modifying a Katana project’s global Graph State Variables on Katana startup.
For information regarding Graph State Variables please look at our Katana User Guide: Graph State Variables.
The approach involves using Katana startup scripts and callbacks working together to set the Graph State Variables.
MORE INFORMATION
The following is an example of how to set the global Graph State variable via the Python tab in Katana’s GUI:
def AddGlobalGraphStateVariable(name, options):
variablesGroup = NodegraphAPI.GetRootNode().getParameter('variables')
variableParam = variablesGroup.createChildGroup(name)
variableParam.createChildNumber('enable', 1)
variableParam.createChildString('value', options[0])
optionsParam = variableParam.createChildStringArray('options', len(options))
for optionParam, optionValue in zip(optionsParam.getChildren(), options):
optionParam.setValue(optionValue, 0)
return variableParam.getName()
name = "Variable Name"
options = ('Option 1','Option 2','Option 3')
AddGlobalGraphStateVariable(name, options)
To automatically run a Python script when launching Katana in interactive mode, you can save a Python script in a UIPlugins folder of a KATANA_RESOURCES environment variable directory path.
However, in order to set a Graph State Variable on a project, the node graph needs to be completely loaded for the project settings to be available for the variable edits to take hold. UIPlugins scripts run before the node graph has loaded in a Katana session and do not initially have access the global Graph State Variables.
To solve this, callbacks are needed in the UIPlugins script. A callback is a piece of Python code added to the Katana environment that runs automatically when various events (such as creating a node or loading a script) happen in Katana. In this case, we need to set onStartupComplete or onSceneLoad callback to run a function that sets the global Graph State Variable right after startup or project load.
Below is an example UIPlugins Python script that sets the global Graph State Variable on Katana launch (also attached):
from Katana import Callbacks
import logging
def onStartupComplete(**kwargs):
log = logging.getLogger("Startup Example")
import NodegraphAPI
name = "Variable Name"
options = ('Option 1','Option 2','Option 3')
variablesGroup = NodegraphAPI.GetRootNode().getParameter('variables')
variableParam = variablesGroup.createChildGroup(name)
variableParam.createChildNumber('enable', 1)
variableParam.createChildString('value', options[0])
optionsParam = variableParam.createChildStringArray('options', len(options))
for optionParam, optionValue in zip(optionsParam.getChildren(), options):
optionParam.setValue(optionValue, 0)
log.info("Katana is now fully initialized and ready for use.")
log = logging.getLogger("Startup Example")
log.info("Registering onStartupComplete callback...")
Callbacks.addCallback(Callbacks.Type.onStartupComplete, onStartupComplete)
If you have further questions, or if you are having any trouble working with using startup scripts to set the global Graph State Variables, then please open a Support ticket and let us know the issue you are encountering and the troubleshooting steps you have taken so far.
For more information on how to open a Support ticket, please refer to the "How to raise a support ticket" article.
FURTHER READING
- Katana User Guide: Graph State Variables
- Katana User Guide: Katana Resources
- Q100385: How to register Callbacks and Event Handlers in Katana using Python to add custom functionality based on user actions
ATTACHMENTS
We're sorry to hear that
Please tell us why