Python in Cinema 4D Manual

Introduction

Cinema 4D has a builtin Python interpreter which can be accessed via the Cinema 4D and c4dpy executable.

Our Python interpreter is based on a vanilla CPython interpreter but not fully identical to it. Using a standard CPython interpreter which is installed on a machine as the Python interpreter of Cinema 4D is therefore not possible. Most third party Python libraries are compatible with our interpreter, but especially C-based libraries can cause problems. The modules of the Cinema 4D Python API are overwhelmingly implemented in C++, the native Cinema 4D C++ API. We strive for feature parity where it is possible, but high-performance and back-end features are usually reserved for the C++ API.

See Python Resources for an overview of external Cinema 4D Python tutorials and learning material.

Version

The current Cinema 4D Python interpreter versions are:

  • Windows: Python 3.11.4 (pipelines/893915622:c23be21, Jun 8 2023, 15:31:26) [MSC v.1929 64 bit (AMD64)]

  • Mac OS: Python 3.11.4 (pipelines/893543668-dirty:1e04aba, Jun 8 2023, 11:27:02) [Clang 14.0.0 (clang-1400.0.29.202)]

Scripting

Cinema 4D loosely makes the distinction between scripting, small pieces of Python code that can be written in and executed from a running Cinema 4D executable, and plugins, more elaborate Python code that must already be present in the boot sequence of the executable. The most important manuals for getting started with scripting are:

Scripting Objects

In addition to plain scripts exist the so called ‘Scripting Objects’ which expose partially the functionalities of some plugin hooks in a simplified form. They are not only great for quick results and technical artist workflows, but are also an excellent learning tool for the Cinema 4D Python API.

Note

Some operations in scripting are not allowed due to functions being called in parallel, as for example inserting an object into the active document from the main function of a Python tag. See Threading Manual for more information on the subject.

Plugins

Plugins integrate seamlessly into Cinema 4D and are indistinguishable from native features. There exist multiple so called plugin hooks, classes which must be implemented to realize a certain type of functionality. Appart from a much deeper access to into the Cinema 4D API, plugins also provide support for multi-language interfaces and defining GUIs in markup files, the so called resource files.

  • Plugin Structure: Describes the makeup of files and folders for a plugin, including multi-language support, and interacting with the boot sequence of Cinema 4D.

The most important plugin hooks are are:

In additon to these most important plugin hooks exist more specialized hooks: