C4DtoA introduces a few custom data types and custom UI widgets (e.g. arrays, the file path of the Arnold drivers, etc.) which have no native python support. Reading and modifying these parameters require special logic and the use of the C4DtoA python API.

Shader Link (sky, light color)

The shader link GUI of an Arnold Sky or Arnold Light object has three modes. It can display a color, a texture or a material link. The following code shows how to query and modify a shader link parameter.

# ---------------------------------------
# query quad light color
# ---------------------------------------

import arnold.custom_gui as arnold_custom_gui

# see the respective resource files for the available parameter ids
# for instance C4DtoA/res/description/ainode_quad_light.h
C4DAIP_QUAD_LIGHT_COLOR = 2010942260

# the returned value is of ArnoldShaderLinkCustomData type
shaderlink = arnold_custom_gui.GetShaderLink(light, C4DAIP_QUAD_LIGHT_COLOR)
if shaderlink is not None:
    if shaderlink.type == arnold_custom_gui.ArnoldShaderLinkCustomData.TYPE_CONSTANT:
        print("%r (constant)" % shaderlink.value)
    elif shaderlink.type == arnold_custom_gui.ArnoldShaderLinkCustomData.TYPE_TEXTURE:
        print("%s [%s] (texture)" % (shaderlink.texture, shaderlink.texture_color_space))
    elif shaderlink.type == arnold_custom_gui.ArnoldShaderLinkCustomData.TYPE_MATERIAL:
        print("%s (material)" % (shaderlink.material.GetName() if shaderlink.material is not None else "<none>"))
# ---------------------------------------
# modify Arnold Sky color
# ---------------------------------------

import arnold.custom_gui as arnold_custom_gui

# see the respective resource files for the available parameter ids
# for instance C4DtoA/res/description/ainode_skydome_light.h
C4DAIP_SKYDOME_LIGHT_COLOR = 268620635

# example 1: set color
shaderlink = arnold_custom_gui.ArnoldShaderLinkCustomData()
shaderlink.type = arnold_custom_gui.ArnoldShaderLinkCustomData.TYPE_CONSTANT
shaderlink.value = c4d.Vector(1.0, 0.0, 0.2)
arnold_custom_gui.SetShaderLink(sky, C4DAIP_SKYDOME_LIGHT_COLOR , shaderlink)
# alternatively you can just simply set the color value
#arnold_custom_gui.SetShaderLink(sky, C4DAIP_SKYDOME_LIGHT_COLOR , c4d.Vector(1.0, 0.0, 0.2))

# example 2: set texture
shaderlink = arnold_custom_gui.ArnoldShaderLinkCustomData()
shaderlink.type = arnold_custom_gui.ArnoldShaderLinkCustomData.TYPE_TEXTURE
shaderlink.texture = "/path/to/my/texture.hdr"
shaderlink.texture_color_space = "linear sRGB"
arnold_custom_gui.SetShaderLink(sky, C4DAIP_SKYDOME_LIGHT_COLOR , shaderlink)
# alternatively you can just set the filename, but note, that you have no control over the color space in this case
#arnold_custom_gui.SetShaderLink(sky, C4DAIP_SKYDOME_LIGHT_COLOR , "/path/to/my/texture.hdr")

# example 3: set material link
shaderlink = arnold_custom_gui.ArnoldShaderLinkCustomData()
shaderlink.type = arnold_custom_gui.ArnoldShaderLinkCustomData.TYPE_MATERIAL
shaderlink.material = my_material
arnold_custom_gui.SetShaderLink(sky, C4DAIP_SKYDOME_LIGHT_COLOR , shaderlink)
# alternatively you can just simply set the material node
#arnold_custom_gui.SetShaderLink(sky, C4DAIP_SKYDOME_LIGHT_COLOR , my_material)

# update the scene
c4d.EventAdd()

Arnold Driver File Path

The file path field of an Arnold driver has multiple modes, such as using the path from the render settings or specifying a custom path. The following code shows how to query and modify a driver file path parameter.

# ---------------------------------------
# query EXR driver path
# ---------------------------------------

import arnold.custom_gui as arnold_custom_gui

# see the respective resource files for the available parameter ids
# for instance C4DtoA/res/description/ainode_driver_exr.h
C4DAIP_DRIVER_EXR_FILENAME = 1285755954

# the returned value is of ArnoldSavePathCustomData type
pathData = arnold_custom_gui.GetSavePath(driver, C4DAIP_DRIVER_EXR_FILENAME)
if pathData is not None:
    typestr = ""
    if pathData.type == arnold_custom_gui.ArnoldSavePathCustomData.TYPE_CUSTOM:
        print("%s (custom)" % pathData.path)
    elif pathData.type == arnold_custom_gui.ArnoldSavePathCustomData.TYPE_CUSTOM_WITH_NAME:
        print("%s (custom - name based on render settings)" % pathData.path)
    elif pathData.type == arnold_custom_gui.ArnoldSavePathCustomData.TYPE_C4D_REGULAR:
        print("render settings (regular)")
    elif pathData.type == arnold_custom_gui.ArnoldSavePathCustomData.TYPE_C4D_MULTIPASS:
        print("render settings (multipass)")
# ---------------------------------------
# modify EXR driver path
# ---------------------------------------

import arnold.custom_gui as arnold_custom_gui

# see the respective resource files for the available parameter ids
# for instance C4DtoA/res/description/ainode_driver_exr.h
C4DAIP_DRIVER_EXR_FILENAME = 1285755954

# example 1: set custom path
pathData = arnold_custom_gui.ArnoldSavePathCustomData()
pathData.type = arnold_custom_gui.ArnoldSavePathCustomData.TYPE_CUSTOM
pathData.path = "/path/to/my/output.exr"
arnold_custom_gui.SetSavePath(driver, C4DAIP_DRIVER_EXR_FILENAME, pathData)

# example 2: use the path defined in the render settings
pathData = arnold_custom_gui.ArnoldSavePathCustomData()
pathData.type = arnold_custom_gui.ArnoldSavePathCustomData.TYPE_C4D_REGULAR
arnold_custom_gui.SetSavePath(driver, C4DAIP_DRIVER_EXR_FILENAME, pathData)

# update the scene
c4d.EventAdd()

Arrays

An array widget defines a list of items. It specifies the number of items and the actual values. For example, the Trace set of a polymesh is a string array. The following code shows how to query and modify array type parameters.

# ---------------------------------------
# query polymesh trace sets
# ---------------------------------------

import arnold.custom_gui as arnold_custom_gui

# trace set is defined in the Arnold tag on the object
ARNOLD_TAG = 1029989
tag = object.GetTag(ARNOLD_TAG)

# see the respective resource files for the available parameter ids
# for instance C4DtoA/res/description/aitag_polymesh.h
C4DAIP_POLYMESH_TRACE_SETS = 550105999

# get array
trace_sets = arnold_custom_gui.GetArray(tag, C4DAIP_POLYMESH_TRACE_SETS)

if trace_sets is not None:
    print("number of trace sets: %d" % len(trace_sets))
    for trace_set in trace_sets:
        print("  %s" % trace_set)
# ---------------------------------------
# modify polymesh trace sets
# ---------------------------------------

import arnold.custom_gui as arnold_custom_gui

# trace set is defined in the Arnold tag on the object
ARNOLD_TAG = 1029989
tag = object.GetTag(ARNOLD_TAG)

# see the respective resource files for the available parameter ids
# for instance C4DtoA/res/description/aitag_polymesh.h
C4DAIP_POLYMESH_TRACE_SETS = 550105999

# set array
arnold_custom_gui.SetArray(tag, C4DAIP_POLYMESH_TRACE_SETS, ["set1", "set2", "set3"])

# update the scene
c4d.EventAdd()

Vector/Color Widget

Some shaders (e.g. add, multiply, mix, etc.) have a special widget which can display the value as a color or as a vector, depending on the selected mode. The following code shows how to query and modify a color/vector type parameter.

# ---------------------------------------
# query multiply.input1
# ---------------------------------------

import arnold.custom_gui as arnold_custom_gui

# see the respective resource files for the available parameter ids
# in case the resource file does not exist, use the GenerateId() function
import arnold.util as arnold_util
C4DAIP_MULTIPLY_INPUT1 = arnold_util.GenerateId("multiply.input1")

# the returned value is of ArnoldVColorCustomData type
vcolor = arnold_custom_gui.GetVColor(shader, C4DAIP_MULTIPLY_INPUT1)

if vcolor is not None:
    print("%f %f %f (%s)" % (vcolor .value.x, vcolor .value.y, vcolor .value.z, 
        "color" if vcolor .type == arnold_custom_gui.ArnoldVColorCustomData.TYPE_COLOR else "vector")
# ---------------------------------------
# modify multiply.input1
# ---------------------------------------

import arnold.custom_gui as arnold_custom_gui

# see the respective resource files for the available parameter ids
# in case the resource file does not exist, use the GenerateId() function
import arnold.util as arnold_util
C4DAIP_MULTIPLY_INPUT1 = arnold_util.GenerateId("multiply.input1")

# example 1: set color value
vcolor = arnold_custom_gui.ArnoldVColorCustomData()
vcolor.type = arnold_custom_gui.ArnoldVColorCustomData.TYPE_COLOR
vcolor.value = c4d.Vector(1.0, 0.0, 0.2)
arnold_custom_gui.SetVColor(shader, C4DAIP_MULTIPLY_INPUT1, vcolor)
# alternatively you can just simply set the color value as maxon.Color type
#arnold_custom_gui.SetVColor(shader, C4DAIP_MULTIPLY_INPUT1, maxon.Color(1.0, 0.0, 0.2))

# example 2: set vector value
vcolor = arnold_custom_gui.ArnoldVColorCustomData()
vcolor.type = arnold_custom_gui.ArnoldVColorCustomData.TYPE_VECTOR
vcolor.value = c4d.Vector(1.0, 0.0, 0.2)
arnold_custom_gui.SetVColor(shader, C4DAIP_MULTIPLY_INPUT1, vcolor)
# alternatively you can just simply set the color value as c4d.Vector type
#arnold_custom_gui.SetVColor(shader, C4DAIP_MULTIPLY_INPUT1, c4d.Vector(1.0, 0.0, 0.2))

# update the scene
c4d.EventAdd()

Color Space


The color space of the image shader and Arnold drivers is a string parameter with a custom UI. It can be set like any other normal string parameters.

# get image shader color space
print "Current color space: %s" % shader.GetParameter(C4DAIP_IMAGE_COLOR_SPACE, c4d.DESCFLAGS_GET_0)

# set image shader color space
shader.SetParameter(C4DAIP_IMAGE_COLOR_SPACE, "sRGB", c4d.DESCFLAGS_SET_0)

# update the scene
c4d.EventAdd()
  • No labels
Privacy settings / Do not sell my personal information / Privacy/Cookies