Q100136: How to copy attributes between scene graph locations via OpScript utilising the procedural workflow

Follow

SUMMARY

This article describes how to use an OpScript node to copy attributes between scene graph locations.

 

MORE INFORMATION

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 cannot 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.
 
AttrCopySS.png
 
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 uses 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 Adding User Parameters section in the Katana User Guide.
 
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))

    We're sorry to hear that

    Please tell us why