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 cannot be queried.
This can be achieved by creating a Geolib3 client, which can request scene data to be produced. Please see the following example:
# 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 more details on Geolib3 and the Op API, please see the Op API section of the Katana Online Help.
If you have further questions, or if you are having any trouble working with the information above, then please open a Support ticket and let us know the issue you are encountering and the troubleshooting steps you have taken so far.
For more information on how to open a Support ticket, please refer to Q100064: How to raise a support ticket.
We're sorry to hear that!Please tell us why.