Create a ticket

Q100351: Querying current frame (and other system Graph State) in a C++ Op


This article will explain how system arguments of the current Graph State, like the current frame time or the number of samples, can be accessed from a custom Op. 

If you are looking for information on how to write and compile a custom Op, please see Q100326: Writing and testing custom Ops.



A common stumbling block when implementing custom Ops is that cook interface functions returning current time (shutterOpen or shutterClose values) or the number of time samples, may not return the correct result unless the node whose Op chain the custom Op is part of, is set up correctly.

This is relevant for example for calls to:


To be able to get the expected return value from these functions it’s necessary to add the System Op Args. It's typically the responsibility of the node (or hosting Op via interface.execOp) to provide these.

If the Op is instantiated via the GenericOp node, its addSystemOpArgs parameter needs to be set to Yes.

If the Op is registered via a custom NodeTypeBuilder, the interface object sent to buildOpChain() has an addOpSystemArgs() method which will add a 'system' GroupAttribute to the Op args. The Op can retrieve and use this.

NOTE: The relevant NodeTypeBuilder function can be found in the Katana Developer Guide.



Attached is an example of a simple NodeTypeBuilder based node type, that creates a single location at /root/world/geo/hello_world of type "hello world", and runs the HelloWorld Op on it. (In this example setting some attributes at /root).

The Op source needs to be compiled before it is ready to use. To do this, please follow the instructions in the $KATANA_ROOT/plugins/Src/ file included in the Katana installation directory.

For more detailed guidance, please see Q100326: Writing and testing custom Ops.


Once the C++ source is compiled into a .so file, this file needs to be placed in an Ops sub-folder of a KATANA_RESOURCES directory, and needs to be placed in a Plugins sub-folder of a KATANA_RESOURCES directory.

For more information on setting up KATANA_RESOURCES, please see the Katana Online Help.

The relevant code to add the 'system' Op arg when appending the Op to the node's Op chain, is the following:

opArgs = FnAttribute.GroupBuilder()



This is equivalent to doing the following:

graphState = interface.getGraphState()
opArgs = FnAttribute.GroupBuilder()
opArgs.set('system', graphState.getOpSystemArgs())


The 'HelloWorld' Op can access this and for example set the current time as an attribute at root:

static void cook(Foundry::Katana::GeolibCookInterface& interface)
    if (interface.atRoot())
        interface.setAttr("Hello", FnAttribute::StringAttribute("World!"));
        interface.setAttr("CurrentTime", FnAttribute::FloatAttribute(Foundry::Katana::GetCurrentTime(interface)));



GraphState::getOpSystemArgs() returns a group containing the 'timeslice' group ('currentTime', 'shutterOpen', 'shutterClose', 'numSamples') and the 'variables' group (graph state variables). This group should be set as the 'system' Op arg: CookInterface calls such as GetCurrentTime and GetGraphStateVariables are convenience functions that call getOpArg("system.[...]").



If you are encountering any issues with the information contained in this article, 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 Q100064: How to raise a support ticket.

Was this article helpful?

We're sorry to hear that

Please tell us why
0 out of 0 found this helpful