Katana: Something to start with

Hallo Leute,

How are you all? Today’s post is about Katana. For people those who are aware about it you can skip the verbose part and directly jump to From here it starts

What is Katana?

Fast and formidable, Katana is a look development and lighting powerhouse that tackles creative challenges with ferocity and ease. It arms artists with the creative freedom and scalability to exceed the needs of today’s most demanding CG-rendering projects.

courtesy Foundry

Katana is integrated with the best renderer Pixars renderman.

Katana is packaged and shipped with python and lua

(just for info, i am not a katana developer i just had to write couple of lines in my office/studio, there is no because, they pay me monthly)

Please excuse me as i am not a very much familiar with the working of the software, it is just the programming aspect of it, I’ll be writing about

From here it starts

OpScript(the worst)

Docs are vague, as there are not many blogs or pages for Katana. I was always redirected to Docs via google(Dr. Strange End Dream seq). The only complain i have, it lacks examples. Assuming people know variable and string(variable– in computer programming it can be defined as to store a certain value eg. integer, string, float to name few of them. string– A string is a sequence of characters). Katana highly depends on variable.

To create some node in Katana

opscript = NodegraphAPI.CreateNode("OpScript",NodegraphAPI.GetRootNode())
Where to find node names?

To get parameters list of the node, this is where variable comes in handy

opscript.getParameters().getChildren()

Below is the result what you get — list of parameters

[<Parameter object at 0x7fa12b2f0978 string 'CEL'>, <Parameter object at 0x7fa12b2f0948 string 'location'>, <Parameter object at 0x7fa12b2f0990 group 'script'>, <Parameter object at 0x7fa12b2f09f0 string 'executionMode'>, <Parameter object at 0x7fa12b2f0a20 string 'applyWhere'>, <Parameter object at 0x7fa12b2f0a50 string 'applyWhen'>, <Parameter object at 0x7fa12b2f0960 string 'modifierNameMode'>, <Parameter object at 0x7fa12b2f0a08 string 'modifierName'>, <Parameter object at 0x7fa12b2f0930 string 'resolveIds'>, <Parameter object at 0x7fa12b2f09a8 number 'recursiveEnable'>, <Parameter object at 0x7fa12b2f09c0 string 'disableAt'>, <Parameter object at 0x7fa12b2f09d8 string 'inputBehavior'>]

To set value in a particular attr

Get and set attr docs link

opscriptparameter = opscript.getParameter('CEL')
opscriptparameter.setValue('/root', 0)

There are two different functions getParameters and getParameter be careful.

There are many different types of parameter that Katana provides, one which a bit confusing is a group inside of a group

<Parameter object at 0x7fa12b2f0990 group 'script'>

You wont be able to get direct result of group unless

opscript plays as the original node and script plays the parameter, for eg. node.getparameter(parameter name). There can be nested groups as well but you can just go with node.getparameter(parameter name.parameter name).

opscriptscriptparam = opscript.getParameter('script').getChildren()

opscriptNodevalue = "this is a test \n for new line)"
opscriptscriptparam[0].setValue(opscriptNodevalue, 0)

The complete code block

opscript = NodegraphAPI.CreateNode("OpScript",NodegraphAPI.GetRootNode())
opscript.setName('OS__RemoveAOVs')
opscript.getParameters().getChildren()
opscriptparameter = opscript.getParameter('CEL')
opscriptparameter.setValue('/root', 0)
opscriptscriptparam = opscript.getParameter('script').getChildren()
opscriptNodevalue = "'this is a test \n for new line'"
opscriptscriptparam[0].setValue(opscriptNodevalue, 0)

This will help you automate your node creation and settings. Please try and let me know.