The following script adds an EXR driver to the scene with a beauty, a diffuse_direct and a custom AOV named 'custom'.

import c4d

# ids taken from C4DtoA/api/include/c4dtoa_symbols.h
ARNOLD_DRIVER = 1030141
ARNOLD_AOV = 1030369

# ids taken from C4DtoA/api/include/util/Constants.h
C4DTOA_MSG_TYPE = 1000
C4DTOA_MSG_INIT_DEFAULTS = 1011

# ids taken from C4DtoA/api/include/util/NodeIds.h
C4DAIN_DRIVER_EXR = 9504161

# ids taken from C4DtoA/res/description/arnold_driver.h
C4DAI_DRIVER_TYPE = 101

# ids taken from C4DtoA/res/description/ainode_driver_exr.h
C4DAIP_DRIVER_EXR_FILENAME = 1285755954

def add_aov(driver, name):
    # create AOV object
    aov = c4d.BaseObject(ARNOLD_AOV)
    aov.SetName(name)
    
    # init defaults (depends on the name)
    msg = c4d.BaseContainer()
    msg.SetInt32(C4DTOA_MSG_TYPE, C4DTOA_MSG_INIT_DEFAULTS)
    aov.Message(c4d.MSG_BASECONTAINER, msg)
    
    # add to the driver
    aov.InsertUnderLast(driver)
def add_driver(nodeType, name, aovs):
    # create the Arnold Driver object
    driver = c4d.BaseObject(ARNOLD_DRIVER)
    driver.SetName(name)
    driver[C4DAI_DRIVER_TYPE] = C4DAIN_DRIVER_EXR
    doc.InsertObject(driver)
    
    # create the AOV objects
    for aov_name in aovs:
        add_aov(driver, aov_name)
        
    return driver

def set_driver_path(driver, param, path):
    path_id = c4d.DescID(c4d.DescLevel(param), c4d.DescLevel(1))
    type_id = c4d.DescID(c4d.DescLevel(param), c4d.DescLevel(2))
 
    driver.SetParameter(type_id, 1, c4d.DESCFLAGS_SET_0)    
    driver.SetParameter(path_id, path, c4d.DESCFLAGS_SET_0)
    
# Execute main()
if __name__=='__main__':
    driver = add_driver(C4DAIN_DRIVER_EXR, "mydriver", ["beauty", "diffuse_direct", "custom"])
    # set the output path
    set_driver_path(driver, C4DAIP_DRIVER_EXR_FILENAME, "/path/to/output.exr")
    # update the scene
    c4d.EventAdd()

Download the full script.

  • No labels