This article describes how to use a OpScript node to copy attributes between scene graph locations.
When working in Katana, attributes on locations can easily be set using a SetAttribute node. However, if you would like to copy an attribute that is set on one location to another location, you can achieve this using an OpScript node and a few lines of code.
Despite the name suggesting a similar function, the AttributeCopy node can not be used for this purpose.
AttributeCopy traverses the copyFrom scene at location fromRoot, and the input scene at location toRoot. From these locations on it expects to find identical hierarchy and location names.
This means that all children of the two locations between which you want to copy attributes have to have the same hierarchical structure and the same names. This ensures that the AttributeCopy node will copy the right attributes to the right locations.
The node works like this because it is designed to copy attributes between scenes in different node graphs that have been modified, but use the same assets and hence their scene graph hierarchies and location names are identical.
To copy attributes between locations in the same scene graph you can use an OpScript that makes use of the CopyAttr() command. You can do this as follows:
1) Create an OpScript node and set its "applyWhere" parameter to "at locations matching CEL"
2) Add three user parameters called "attrFrom", "attrTo" and "sourceLocation". For instructions on how to add user parameters to a node please refer to the User Parameter section in the Katana Online Help
3) The value of the "sourceLocation" parameter should be the path to the scene graph location you want to copy the attribute from
4) The CEL statement should be the path to the scene graph location you want to copy the attribute to
5) Type the name of the attribute you want to copy from in the "attrFrom" text field.
6) Add the name of the attribute you want to copy to as the "attrTo" parameter value.
7) In the "Script" parameter of the OpScript node add this lua code:
local attrFrom = Interface.GetOpArg("user.attrFrom"):getValue()
local attrTo = Interface.GetOpArg("user.attrTo"):getValue()
local sourceLocation = Interface.GetOpArg("user.sourceLocation"):getValue()
Interface.CopyAttr(attrTo, attrFrom, true, sourceLocation)
Please note that this will only work when sourcing local attributes. If the attribute you want to copy is inherited from a parent location, please change the last line to:
Interface.SetAttr(attrTo, Interface.GetGlobalAttr(attrFrom, sourceLocation))
Please see the attached screenshot for an example of what the node parameters should look like. In this case prmanStatements.attributes.visibility.camera attribute, which was set for boot_left_1Shape in the prmanObjectSettings node, is copied to /root/world/geo/manScene/body_main/geometry and everything underneath this location will inherit the attribute.
OpScript, AttributeCopy, SetAttribute, copy attributes, scenegraph locations, different hierarchy, source destination, Katana
Was this article helpful?
2 out of 3 found this helpful