Q100443: Scripting and Programming in Katana
Katana supports three languages for adding custom code to the application: Python, Lua and C++. This article gives an overview of how to get started with scripting and programming in Katana and which tasks each language is most appropriate for.
Each of the available languages in Katana has its own set of strengths, so it depends on the specific use case which one is best suited.
Python is used widely for rapid application development, especially in the context of APIs to allow users to customize the application, for example when working with projects, working with nodes, customising node types, customising the user interface, or Python-based parameter expressions.
Further examples are described in the Katana Online Help on Scripting with Python and the following articles which go into detail about different Python workflows:
- Q100091: Rendering multiple frames in Katana GUI mode
- Q100108: Add custom menu items to the context menu of nodes
- Q100109: Parameter Expressions and adding custom functions
- Q100401: Creating a Shelf Item in Katana
- Q100385: Callbacks and event handlers in Katana
- Q100439: Modifying the global Graph State Variables on startup
- Q100372: Renaming input and output ports with Python
- Q100358: How to query attributes of scene graph locations via Python using a Geolib3 Client
- Q100277: Positioning nodes in the Katana Node Graph via Python
- Q100098: Creating your own custom tab in the UI
PYTHON - PERFORMANCE CONSIDERATIONS
Where faster performance is required, Python isn’t always an ideal choice (partly due to the dreaded GIL).
In the context of parameter expressions, a faster alternative to Python expressions is available for simple expressions that reference nodes or parameters. This is called Reference Expressions, please follow the link to the Katana Developer Guide for further information.
Previous releases of Katana have suffered from stability issues when running Python-based AttributeScripts and asset plug-ins out-of-process through the so-called Katana ProcessManager.
While the stability of ProcessManager was improved in the Katana 2.5 release (see TP 128448 in the Katana 2.5v1 Release Notes), the performance of Python especially in the context of scene evaluation is problematic.
Lua offers better performance, making it a preferred scripting language for scene graph processing operations using OpScript nodes.
Lua is used within the OpScript node in Katana. Using OpScript/Lua it’s possible to access the Op API, which is both faster and more powerful than Python. In particular, the OpScript node allows you to modify the structure of the scene graph hierarchy, such as deleting locations, creating new child locations as well as setting and editing attributes.
Lua represents a reasonable balance between fast development turnaround time for developing operations on the scene graph (also for prototyping more complex operations that are planned to be implemented as Op Types later), and fast execution time and stability as part of cooking a scene.
In certain situations it may be advisable to implement a custom Op type plug-in instead of using OpScript/Lua. Whether this is of advantage depends on the actual use case at hand: the complexity of a project and its assets, the number of operations to be performed, the number of scene graph locations to target. It's advisable to process FX data like particle simulations in Ops/C++, rather than OpScript/Lua.
For an introduction to using OpScript and the Op API, please look at the OpScript tutorials in the Help > Example Projects menu in Katana.
You may also be interested in the following articles:
- Q100136: Copying attributes between any scene graph locations using an OpScript
- Q100291: Collecting CEL statements in an OpScript
When performance is critical, for example when working with large data sets, a Lua OpScript can be ported to a C++ Op type plug-in.
Please see the Katana Developer Guide for documentation of the interface, and refer to the example “HelloWorld” Op shipped with the Katana source code in the following location: $KATANA_ROOT/plugins/Src/Ops/HelloWorld
Build instructions can be found here: $KATANA_ROOT/plugins/Src/README.md
For some further hints and instructions on compiling an example Op, please see the following article: Q100326: Writing and testing custom Ops
You may also be interested in the following content:
Please refer to the Katana Online Help and Developer Guide for guides and further reference for each language:
- Q100326: Writing and testing custom Ops
- Q100351: Querying current frame (and other system Graph State) in a C++ Op
We're sorry to hear that!Please tell us why.