[Arnold] [Python] Iterating over the shape nodes in a scene

Here’s a snippet that loops over the shape nodes in an ASS file.

from arnold import *


# Required if the ASS file uses any SItoA shaders


# Iterate over all shape nodes
iter = AiUniverseGetNodeIterator(AI_NODE_SHAPE);
while not AiNodeIteratorFinished(iter):
	node = AiNodeIteratorGetNext(iter)
	print "[script] AiNodeGetName: {0}".format( AiNodeGetName( node ) )
	ne = AiNodeGetNodeEntry( node )
	print "[script]  AiNodeEntryGetName: {0}".format( AiNodeEntryGetName( ne ) )
	print "[script]  AiNodeEntryGetType: {0}".format( AiNodeEntryGetType( ne ) )
	print "[script]  AiNodeEntryGetTypeName: {0}".format( AiNodeEntryGetTypeName( ne ) )

This would print something like this:

C:\solidangle\scripts>python shapes.py
[script] AiNodeGetName: root
[script]  AiNodeEntryGetName: list_aggregate
[script]  AiNodeEntryGetType: 8
[script]  AiNodeEntryGetTypeName: shape
[script] AiNodeGetName: cube.SItoA.1000
[script]  AiNodeEntryGetName: polymesh
[script]  AiNodeEntryGetType: 8
[script]  AiNodeEntryGetTypeName: shape

Note the root node of type list_aggregate. It’s shape used internally by Arnold. Just be aware that that root node is there in the universe, because even if you load an ASS file that contains just polymesh nodes, there will be a root node that you’ll have to skip over.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s