Getting shader info from an ASS file

First, set things up so you can use the Arnold Python API. On Windows:

set PATH=C:\Users\blairs\AppData\Local\Programs\Python\Python39;%PATH%
set PYTHONPATH=C:\solidangle\arnold\Arnold-\python

rem Sometimes necessary
set PATH=C:\solidangle\arnold\Arnold-\bin;%PATH%

Then, run this Python script, which does the following:

  • Sets the logging verbosity
  • Loads an ASS file
  • Loops over all the shader nodes.
  • If a shader is a standard_surface, inspect the ID AOV parameters.
from arnold import *
# Required if the ASS file uses any SItoA shaders
# Iterate over all shader nodes
iter = AiUniverseGetNodeIterator(AI_NODE_SHADER);
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 ) ) )

    if AiNodeIs( node, "standard_surface" ):
        # Plain color ID AOVs are easy
        aov_id1 = AiNodeGetStr( node, "aov_id1" )
        print( "[script]  aov_id1={0}".format( aov_id1 )  )   
        id1 = AiNodeGetRGB( node, "id1" )
        print( "[script]  id1={0} {1} {2}".format( id1.r, id1.g, id1.b)  )   

        # ID AOVs that use a linked shader take a bit more work     
        aov_id2 = AiNodeGetStr( node, "aov_id2" )
        print( "[script]  aov_id2={0}".format( aov_id2 )  )   
        if AiNodeIsLinked( node, "id2" ):
            id2 = AiNodeGetLink( node, "id2" )
            print( "[script]  id2={0}".format( AiNodeGetName( id2 ) ) )


Leave a Reply

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

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

Google photo

You are commenting using your Google 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 )

Connecting to %s