Share

Python API - Arnold for Cinema4d

C4DtoA ships with a Python API (since C4DtoA 4.2.0), which allows you to work with Arnold-specific components, such as the Arnold Material, custom GUI elements, etc.

The API is located in specific Python modules in the C4D_HOME/library/scripts/arnold folder (in case of a default install). In your Python script, you have to make sure the scripts folder is added to the search path:

import c4d, os, sys

# add the script folder to the system path
scripts_folder = os.path.join(c4d.storage.GeGetC4DPath(c4d.C4D_PATH_LIBRARY), "scripts")
if scripts_folder not in sys.path:
    sys.path.append(scripts_folder)

Note: The plugin can be installed in the user plugins folder or to a custom location, instead of the application folder. The following code snippet adds all potential script locations to the search path.

import c4d, os, sys

# add scripts folders to the system path
scripts_folders = [
    # application library folder
    os.path.join(c4d.storage.GeGetC4DPath(c4d.C4D_PATH_LIBRARY), "scripts"),
    # user library folder
    os.path.join(c4d.storage.GeGetC4DPath(c4d.C4D_PATH_LIBRARY_USER), "scripts")
]
# custom library folder
if "C4D_SCRIPTS_DIR" in os.environ:
    scripts_folders.extend(os.environ["C4D_SCRIPTS_DIR"].split(';'))

for scripts_folder in scripts_folders:
    if scripts_folder not in sys.path:
        sys.path.append(scripts_folder)

After the search path is set correctly, you can import the specific Arnold modules, for instance:

import arnold.util as arnold_util
from arnold.material import *

The following pages contain examples of how to use the API and how to query and modify Arnold-related nodes in the scene.

Was this information helpful?