After 3 years of Python scripting, I finally reached that point where I can confidently say that I roughly know, what I am doing. Then I fall in love with Katana and while interface and node graph stuff can be accessed/modified via Python, OpScripts are – for performance reasons – Lua based.
Well, off to something new then. tongue
I consider this blog post as a dynamic place that I will update whenever I make some progress. I am not sure how this will turn out, but I think I’ll start off with some code snippets. If anybody stumbles upon this, feel free to leave a comment, correct me, help me, suggest anything you think that might be useful. I would greatly appreciate it.
Update: This post got bigger than I expected, so I figured, my Python to Lua Cheat Sheet deserves its own blog post smile
OpScript in Katana
To create an OpScript in Katana, just create an OpScript node and define your CEL statements. The OpScript will now loop over the defined scene graph locations and run the code. As long as executionMode is “immediate” the code is run, whenever you “leave” the script box. That is, whenever you click somewhere else in the Interface. If you have some unfinished code which you know, would throw an error and you don’t want Katana to freak out, you can change this setting to deferred. Now the code is only run when you have either an OpResolve node, or you can conveniently toggle Scene Graph Implicit Resolvers from the top menu bar.
Now let’s start really simple.
--get an attribute Interface.GetAttr("material.parameters.color")
To find out the attribute name you usually just need to chain the group names
in the attributes panel with a dot. Alternatively you can hover over the attribute
and the tooltip shows the whole path.
--print an attribute to the shell to see if it worked local my_float = Interface.GetAttr("material.parameters.roughness") print (my_float)
However, this will return
This might be what you want, or maybe not. If you want to do some calculations, you can use getValue() to get the actual value.
local my_float = Interface.GetAttr("material.parameters.color"):getValue() print (my_float) my_float = my_float + 0.1 print (my_float)
to be continued…