c4dpy Manual

c4dpy.exe/app is an executable that runs Cinema 4D in Python command-line mode.
It is not only an interpreter, it brings extra features for daily Python development with external code editors/IDEs: auto-completion and debugging.

Warning

Due to a bug since R21, c4dpy is not anymore supported by any Python IDE. However auto-completion can be achieved since S22, see Autocompletion Manual.
For more information see c4dpy.exe and VS Code.

Installation

Warning

c4dpy needs a valid installation of Cinema 4D it’s not a standalone.

Note

c4dpy should have the same version than the folder is in it.

R21+:

Since R21 c4dpy is part of the normal installation process so you don’t need to install anything.
However due to the new licensing system, before any usage of it, launch it at least one time in order to license c4dpy otherwise you can pass these argument while executing c4dpy:
  • g_licenseUsername=”[username]”// inform Cinema 4D about the username to authenticate on https://id.maxon.net.

  • g_licensePassword=”[password]” // inform Cinema 4D about the password to authenticate on https://id.maxon.net.

R20:

  1. Download the c4dpy version which match your Cinema 4D version.

  2. Extract the c4dpy executable according to the target operating system.

  3. Copy the extracted c4dpy executable to the Cinema 4D installation directory along with the other executable files:

../_images/c4dpy_installdirectory.png

Verify Installation

Windows

  1. Open Command Prompt.

  2. Drag c4dpy.exe executable into the Command Prompt and press enter.

  3. c4dpy should run without error and ask your MyMaxon account. Next start you will not need to login again.

  4. Python interactive interpreter >>> is now available.

Mac

  1. Open Terminal.

  2. Right-click on c4dpy.app and select Show Package Contents.

  3. Navigate to the Contents/MacOS directory.

  4. Drag the c4dpy file into the Terminal window and press return.

  5. c4dpy should run without error and ask your MyMaxon account. Next start you will not need to login again.

  6. Python interactive interpreter >>> is now available.

Command-Line

c4dpy runs a script with:

c4dpy script.py

The following command invokes script.py and passes arg argument:

c4dpy script.py -arg

Note

Arguments can be accessed by sys.argv.

The command below loads the module in file.py and passes arg argument:

c4dpy -m file.py -arg

c4dpy also executes Python code in a string:

c4dpy -c "print('Hello')"

Editor Integration

Since c4dpy is just a Python interpreter like any other, it can be integrated with the developing environment of your choice.

Sublime Text

This guide has been written for SublimeText 3.2.2, some of the described steps might be slightly different for future or past versions of the application.

  1. Run Tools > Build Systems > New Build System from the main menu to create a new build system.

../_images/sublime_build_menu.png
  1. SublimeText will open a file for you, replace its content with the following:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
{
    "selector": "source.python",
    "cancel": {"kill": true},
    "variants": [
        {
            "name": "c4dpy",
            "cmd": ["c4dpy", "-u", "$file"],
            "file_regex": "^[ ]*File \"(...*?)\", line ([0-9]*)",
        },
        {
            "name": "CPython",
            "cmd": ["py", "$file"],
            "file_regex": "^\\s*File \"(...*?)\", line ([0-9]*)"
        }
    ]
}
  1. This example assumes a separate standalone CPython installation to be on the machine which we want to run alongside with c4dpy in this Python build environment. If this is not the case, one can delete the lines ten to fourteen in the file listing above. This example also assumes the user to having set up environment variables for both the CPython and c4dpy interpreter; c4dpy for c4dpy and py for CPython. Alternatively the first cmd argument can also be an absolute path, e.g.:

1
2
3
4
5
6
7
"cmd": ["c4dpy", "-u", "$file"],
// Should become something like this, modify to your Cinema 4D directory.
"cmd": ["C:\Program Files\Maxon\S24\c4dpy.exe", "-u", "$file"],

"cmd": ["py", "$file"],
// Should become something like this, modify to your CPython directory.
"cmd": ["C:\compilers\python3.9\python.exe", "$file"],
  1. Save the file with CTRL + S, SublimeText will open a file dialog already set to the user packages path. Save the build environment settings under the name it should appear in menus, e.g., Python-Environments.sublime-build.

  2. The build environment will now appear in the build menu to be selected as the active build environment as shown in the screen under point one.

  3. A Python file like shown below can now be run with either of the defined Python interpreters.

../_images/sublime_setup_0.png
  1. Pressing CTRL + SHIFT + B or running Tools > Build With will cause SublimeText to prompt a popup asking for the interpreter to run the file with.

../_images/sublime_setup_1.png
  • Running the file with c4dpy:

../_images/sublime_setup_2.png
  • Running the file with CPython:

../_images/sublime_setup_3.png
  1. After having set the sub-environment with CTRL + SHIFT + B all consecutive Build invocations (CTRL + B) will run that currently selected sub-environment.

Visual Studio Code

c4dpy can also be run as a Python interpreter in Visual Studio Code.

  1. Open Visual Studio Code and run File > Preferences > Settings

../_images/vscode_setup_0.png
  1. Type ‘Default Interpreter’ into the search bar of the user settings to find the ‘Python: Default Interpreter Path’ setting. Set it to the path of a c4dpy interpreter.

../_images/vscode_setup_1.png
  1. c4dpy should now appear in the available Python interpreters in the interpreter selector in the bottom left corner of Visual Studio Code when having a Python file opened.

../_images/vscode_setup_2.png
  1. With it activated, a file can be interpreted either by pressing CTRL + F5 or by pressing debug play button in the top right corner.

../_images/vscode_setup_3.png
  1. Debugging (F5) will not work out of the box.

Visual Studio

c4dpy has to be setup on a per project basis in Visual Studio.

  1. Open Visual Studio and start a new Python Application project.

../_images/vs_setup_0.png
  1. In the project add a new Python environment.

../_images/vs_setup_1.png
  1. In the dialog select Existing Environment and then setup the values like shown below.

../_images/vs_setup_2.png
  1. Pressing CTRL + F5 will now run the defined startup file of the project.

../_images/vs_setup_3.png
  1. Debugging (F5) will not work out of the box.