Q100358: How to query attributes of scene graph locations via Python using a Geolib3 Client
This article explains how scene graph data like location attributes can be produced and queried using Python.
Users may wish to write Python scripts that query the value of attributes on scene graph locations. To make this possible, the scene has to be cooked first. A cook represents an evaluation of the scene graph, meaning the node graph has to be evaluated to calculate the scene data. If this step doesn’t happen, the attribute data does not exist and can not be queried.
This can be achieved by creating a Geolib3 client, which can request scene data to be produced. Please see the following example (taken from http://tomcowland.com/katana/archives/748):
# We first need to get a hold of the runtime the UI is using runtime = FnGeolib.GetRegisteredRuntimeInstance() # Transactions are used to batch together actions txn = runtime.createTransaction() # Make a client, and attach it to an Op in the tree, we get the Op from a reference to a Node. client = txn.createClient() op = Nodes3DAPI.GetOp(txn, NodegraphAPI.GetNode('Render')) txn.setClientOp(client, op) # Commit the transaction to the runtime, if we don't the client will exist, but won't yet be pointing to an Op runtime.commit(txn)
Then you can use the client to cook a location and inspect its attribute values, for example to get the centerOfInterest attribute of a camera location:
location = client.cookLocation('/root/world/cam/camera')
attrs = location.getAttrs()
COI = attrs.getChildByName('geometry.centerOfInterest')
For further information on Geolib3 and the Runtime, please see the Core Concepts with Geolib 3 section in the Katana Online Help, as well as the blog post referenced above.
We're sorry to hear that!Please tell us why.