Script Manager

Open the Script Manager (Extensions / Script Manager).

The Script Manager lets you create and manage Python. scripts and even assign new icons so that you can later easily access these scripts in the Extensions menu under User Scripts. It is no longer necessary to create plugins.

Scripts created using the Script Manager are saved to the user Library / Scripts directory.

User Buttons

Using the script field

The following interactive functions are available for the script field:

File Menu

New Script

A new, untitled script will be created (however, scripts that were not saved will be saved to the prefs/_last_script folder in the user directory with the file extension *.py (Python); for example, if a script should cause the application to crash the script will itself will not be lost).

Open Script...

Use this command to load non-write protected (non-encrypted) Python codes (*.py). The file selection dialog will jump directly to the proper directory.

Import Script...

Use this command to import code into the Script Manager. The following file formats can be imported:

*.py (Python)

Save Script

Save Script as...

Save the script currently selected under Script (unsaved scripts have a * in their name). A new name can be assigned if you select Save Script As. Scripts will be saved by default to the "library / scripts" user directory.

Save All Scripts

All new or modified scripts will be saved.

Delete Script from Disk

The script currently selected under Script will be deleted after a security prompt is confirmed by you.

Duplicate Script

Duplicates the script currently selected under Script.

Load Icon...

Select a square bitmap that you want to use for this script. This icon will be displayed in the corresponding menu's icon list and even in the Command Manager. Even alpha channels will be displayed.

Render Icon

If you are looking for the ideal image to use for your icon, this is the button for you – the current Cinema 4D scene will be rendered and this image can be used as your icon.

2023

Send to IDE

This command can be used to send the script content of all active scripts to all IDEs connected with Cinema 4D. This command is also available in the Script Manager layout next to the Start/Stop Code Exchanger button. Note also the additional Code Exchanger settings and commands in the Script Manager's Edit menu.

Edit menu

Undo

Redo

Changes made to the code can be undone or redone.

Cut

Cuts out the selected code and copies it to the cache.

Copy

Copies the selected code to the cache.

Paste

Pastes the cut or copied code from the cache to the selected location.

Delete

Deletes the selected code.

Select All

Deselect All

Selects or deselects all selected code. The code can also be deselected by clicking anywhere within the code window.

2023

Start/Stop Code Exchanger

With the introduction of Cinema 4D R26, a plug-in was added that communicates with the Visual Studio Code Extension. In Version 2023.2, this Code Exchanger plug-in was integrated directly into Cinema 4D so that it no longer has to be installed manually. This Visual Studio Code Extension must, however, still be installed manually and can be found here: https://marketplace.visualstudio.com/items?itemName=maxonc4dsdk.cinema4d-connector.

The Code Exchanger function makes it possible to communicate between Cinema 4D and Visual Studio Code So that developers can send and/or execute a Python script from Cinema 4D to Visual Studio and vice-versa.

In addition, the Visual Studio Code Extension improves the developer experience for all Cinema 4D developers because it makes it offers auto-complete the *.c4d Python package, debugging support, syntax highlighting for *.res and *.str files and even the output of the Python console directly in Visual Studio Code.

This function can be enabled or disabled via this command or via the </> icon in the header of the Script Manager. If the Code Exchanger is enabled, this icon will have a blue background.

As soon as the Visual Studio Code Extension is installed you will see a red field with C4D X at the bottom left of the interface. If you click on it, a connection to the previously activated Code Exchanger in Cinema 4D will automatically be created and the color of this field will change in the default status bar.


A new C4D icon will appear in the Visual Studio Code status bar

Sending Code from Cinema 4D to Visual Studio Code

Create a new Python file in the Script Manager or you use an existing one. Using the Send to IDE command in Script Manager's File menu you can send the script content of the active script to all IDEs that are connected with Cinema 4D. This command can also be found at the top of the Script Manager as an icon, directly next to the Start/Stop Code Exchanger icon.

 

Visual Studio Code Functions

c4d Python Packet Auto-complete

The automatic completion for the c4d package in Visual Studio Code makes it possible for you to work faster without constantly having to check the documentation. In order for the extension to work, the c4d_path setting must be defined. This is defined here when Visual Studio Code is connected with Cinema 4D for the first time.


Commands

All commands for this extension can be found by pressing Ctrl + Shift + P and searching for C4D. They all require that Visual Studio Code is connected with Cinema 4D.

  • Open script in the Script Manager: Open the active script from the Visual Studio Code Editor into the Cinema 4D Script Manager. Visual Studio Code should be connected with Cinema 4D in order to execute this command.
  • Save script to disk: Works as expected. Saving the file will update the script both in the IDE and in Cinema 4D.
  • Unknown script from Visual Studio Code: A new temporary file will be created in Cinema 4D. This file will be added back to Visual Studio Code and it should be used for the communication with Cinema 4D instead of the previously unnamed file.
  • Temporary script from Cinema 4D: Works as expected. Ctrl+S will send the contents to Cinema 4D. The auto completion will not work here.
  • Execute in Cinema 4D as script in the Script Manager: Execute the script directly in Cinema 4D. Visual Studio Code should be connected with Cinema 4D in order to execute this command.
  • Files or scripts saved to the hard drive from a tempprary Cinema 4D script. Update the content of the script in Cinema 4D and execute the script.
  • Unknown script from Visual Studio Code: Create a new temporary Python script in Cinema 4D. Execute the script and delete it from Cinema 4D.
  • Debugging in Cinema 4D as a script in the Script Manager: Start a debugging session for the respective script in Cinema 4D. Encrypted Python files (.pypv, .pype) will be ignored and cannot be debugged. Visual Studio Code should be connected with Cinema 4D to execute this command.
  • The file was saved to the hard drive: Will work as expected.
  • Scripts from a temporary Cinema 4D script: Not supported.
  • Unknown script from Visual Studio Code: Not supported.
  • Switch connection with Cinema 4D: Switches the current connection between Cinema 4D and Visual Studio Code. This is comparable with clicking on the C4D status bar in the bottom-left corner of Visual Studio Code.


Output in the Python Consile

As soon as Visual Studio Code is connected with Cinema 4D, new content from the Python Console will also be displayed in the Visual Studio Code Console Cinema 4D.


Highlighting Syntax for *.res and *.str Files

In order for the extension to work, the c4d_path setting must first be defined. It's defined when Visual Studio Code is connected with Cinema 4D for the first time.


Extension Settings

This extension offers the following settings:

  • c4d.path: Path to the Cinema 4D directory, which is used for the automatic completion. If this path is not defined or is incomplete, it will automatically be defined when Visual Studio Code and Cinema 4D are connected for the first time.
  • c4d.ip: IP address that is used for the connection with Cinema 4D.
  • c4d.port: The port that is used for the connection with Cinema 4D.


Known Issues

  • The automatic completion does not work in conjunction with temporary scripts from Cinema 4D that have a path that looks as follows: Root@12345678/Scripts@12345678/untilted.py aussieht.
  • If the Load Scropt in Script Manager is used for an unnamed file, a new temporary file will be created in Cinema 4D and sent back to Visual Studio Code. This file should be used for the data exchange from/to Cinema 4D.
  • In the first debugging session, a prompt about the outdated connection with ptvsd will be displayed. This is a false alarm and can be ignored.


Code Exchanger Settings

In this dialog window you can define which Code Exchanger should be used and which port should be used for communication.

Dialog

Icon

This is the icon (see next image) that has been assigned to the current script. An icon can be assigned or changed by selecting Load Icon … or Render Icon …

You can simply drag & drop this icon onto any Icon Palette or into a Menu Manager.

NoteIn order to save the resulting configuration, you must select Window / Customize / Save as Startup Layout.

Script

Here, all scripts in the directory library / scripts in the user directory will be shown with their file names. Scripts marked with a small x are not yet saved.

Shortcut

Click on this button to open the Command Manager where you can assign a keyboard shortcut to this script.

Execute

Executes the script. Error messages will be output to the Console (main menu: Extensions / Console).