c4dpy

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.

Install

Warning

c4dpy needs a valid installation of Cinema 4D R20.

To install c4dpy, follow the steps below:

  1. Download the latest c4dpy archive.
  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 Install

Windows

  1. Open Command Prompt.
  2. Drag c4dpy.exe executable into the Command Prompt and press enter.
  3. c4dpy should run without error and enter Python interactive interpreter >>>.

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 enter Python interactive interpreter >>>.

Editor/IDE Setup

Note

This section shows how to add c4dpy interpreter to code editor and IDE softwares. The screenshots may not reflect changes in future versions of these programs but the steps should remain the same.

Visual Studio Code

Windows

  1. Install the Python extension for Visual Studio Code.
  2. Select the File > Preferences > Settings command (or Ctrl+Comma shortcut).
  3. Search the settings for python.pythonPath and set it to point to the full path of the c4dpy.exe file. For example:
../_images/c4dpy_vscode_win.png

The Python Path is set in the User Settings so c4dpy.exe interpreter is used globally by Visual Studio Code.

Note

Settings can be specified by user, workspace or folder.

  1. Restart Visual Studio Code.

Note

With c4dpy version R20 SP1, debugging fails because ptvsd module cannot be found. The Python extension for Visual Studio Code uses this module to debug.
The workaround is to copy the ptvsd module folder from the Visual Studio Code user preferences to C:Users{username}AppDataRoamingMAXON{cinemaversion}python27libs.

Mac

  1. Install the Python extension for Visual Studio Code.
  2. Select the Code > Preferences > Settings command (or cmd+comma shortcut).
  3. Search the settings for python.pythonPath and set it to point to the full path of the c4dpy Terminal file. For example:
../_images/c4dpy_vscode_mac.png

The Python Path is set in the User Settings so c4dpy interpreter is used globally by Visual Studio Code.

Note

Settings can be specified by user, workspace or folder.

  1. Restart Visual Studio Code.

Note

With c4dpy version R20 SP1, debugging fails because ptvsd module cannot be found. The Python extension for Visual Studio Code uses this module to debug.
The workaround is to copy the ptvsd module folder from the Visual Studio Code user preferences to /Users/{username}/Library/Preferences/MAXON/{cinemaversion}/python27/libs.

PyCharm

Windows

  1. PyCharm requires that Python interpreters be named python so copy and/or rename c4dpy.exe to python.exe.
  2. Select the File > Settings command (or Ctrl+Alt+S shortcut) and switch to Project Interpreter under Project.
  3. Click the wheel on the right of Project Interpreter dropdown and select Add.
../_images/c4dpy_pycharm_win1.png
  1. Choose System Interpreter and select the renamed python.exe file.
../_images/c4dpy_pycharm_win2.png
  1. Click OK and wait PyCharm adds the interpreter.

Mac

  1. PyCharm requires that Python interpreters be named python so copy and/or rename c4dpy.app to python.app.
  2. Right-click on c4dpy.app and select Show Package Contents, navigate to the Contents/MacOS directory and rename c4dpy to python.
  3. Select the PyCharm > Preferences command (or cmd+comma shortcut) and switch to Project Interpreter under Project.
  4. Click the wheel on the right of Project Interpreter dropdown and select Add.
../_images/c4dpy_pycharm_mac1.png
  1. Choose System Interpreter and select the renamed python.app/Contents/MacOS/python file.
../_images/c4dpy_pycharm_mac2.png
  1. Click OK and wait PyCharm adds the interpreter.

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')"