Script Manager

Call up the Script Manager via Extensions / Script Manager.

With the Script Manager you can create and manage Python scripts and even assign icons so that you can call them up later from the Extensions menu under User scripts. It is no longer necessary to create plug-ins.

Scripts created with the Script Manager are permanently stored in the Library / Scripts directory of the default settings directory.

Control elements

Operation within the script input field

The following things work within the input field:

File menu

New Script

A new unnamed and unsaved script will be created (however, unsaved scripts are stored in the preferences directory under Prefs/_last_script with the file extension *.py (Python); if a script causes a program crash, the script will not be lost).

Open Script...

Use this to load unprotected (unencrypted) Python scripts (*.py). The file selection dialog will jump directly to the appropriate preset directory.

Import Script...

You can use this to import code into the Script Manager. The following file formats are possible: *.py (Python).

Save Script

Save Script as...

Use this to save the script just selected under Script (unsaved scripts have a * in their name). A new name can be assigned with Save script as. The default settings will be saved in your default settings directory under Library/scripts.

Save All Scripts

This will save all newly-created or modified scripts.

Delete Script from Disk

This will delete the script currently selected under Scripts after a confirmation prompt.

Duplicate Script

This command duplicates the script just selected under Script.

Render Icon

If you do not have a suitable image at hand for your newly-created script, this function is the right one for you. This renders the current Cinema 4D scene and uses the result as an icon.

Load Icon...

Use this to select a primarily square bitmap, which will then be used as the icon for this script and will also be displayed accordingly in the menu, in the icon bar and even in the Command Manager. Any existing alpha channel of the bitmap will be taken into account.

Send to IDE

This command lets you send the script content of the active script to all IDEs connected to Cinema 4D. This command will also be available in the Script Manager layout next to the Start/end code exchanger button. Please also note the other code exchanger presets and commands in the Edit menu of the Script Manager.


Edit Menu

Undo

Redo

This can be used to undo and restore code edits.

Cut

Cut out selected code snippets and copy them to the clipboard.

Copy

Use this to copy selected code snippets to the clipboard.

Paste

Use this to paste code in the clipboard at the cursor position.

Delete

Use this command to delete selected code.

Select All

Deselect All

Select or deselect all code displayed in the window. Alternatively, you can also deselect the code by clicking in any area of the code window.

Start/Stop Code Exchanger

With R26, a plugin was introduced in Cinema 4D that communicates with a Visual Studio code extension. With version 2023.2, this code exchanger plugin was integrated directly into Cinema 4D so that you no longer need to install it manually. However, the Visual Studio Code extension must still be installed manually and can be found here: https://marketplace.visualstudio.com/items?itemName=maxonc4dsdk.cinema4d-connector.

The Code Exchanger feature enables communication between Cinema 4D and Visual Studio Code, allowing developers to send and/or execute a Python script from Cinema 4D to Visual Studio Code and vice versa.

In addition, the Visual Studio Code extension enhances the development experience of all Cinema 4D developers by enabling auto-completion of the `c4d` Python package, debugging support, syntax highlighting for ".*res" and ".*str" files, or even the output of Cinema 4D's Python console directly in Visual Studio Code.

This functionality can be switched on or off via this command or via the </> icon in the header of the Script Manager. An icon with a blue background indicates an active code exchanger.

As soon as the Visual Studio Code extension is installed in Visual Studio Code, you should see a red box with "C4D X" at the bottom left of the window in the status bar. When you click on it, a connection to the previously activated Code Exchanger in Cinema 4D will automatically be established so that the color of the box in the standard status bar changes


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

Send code from Cinema 4D to Visual Studio Code

Create a new Python file in the Script Manager or use an existing one. The Send to IDE command in the File menu of the Script Manager lets you send the script content of the active script to all IDEs connected to Cinema 4D. This command can also be found in the Script Manager layout as an icon at the top right, directly next to the icon for Start/end code exchanger.

Visual Studio code functions

c4d Python package auto-complete

The auto-completion for the c4d package in Visual Studio Code lets you work faster without always having to look in the documentation. The c4d.path setting must be defined for the extension to work. It is defined when Visual Studio Code establishes a connection to Cinema 4D for the first time.


Commands

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


Output in the Python console

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


Syntax highlighting for *.res and *.str files

The c4d.path setting must be defined for the extension to work. This is defined when Visual Studio Code establishes a connection to Cinema 4D for the first time.


Extension settings

This extension comes with the following settings:


Known problems


Code Exchanger Settings

Use this dialog to define which code exchanger should be used and which port should be used for communication.

Dialog

Icon

Here you can see the icon assigned to the current script. You can assign your own icons with Load icon or Render icon.

You can simply drag and drop this icon into an existing icon bar, a newly-created command palette or into the Menu Manager.

Note: This configuration will only be saved permanently when you call up Main menu: Window / Customize / Save as start layout.

Script

All scripts in the library / scripts folder of the user directory are displayed here with the file name. If scripts are marked with a small x, these scripts have not yet been saved.

Keyboard shortcuts

Click on this button to call up the Command Manager, where the current script is already highlighted and is waiting for you to assign a keyboard shortcut to it.

Execute

Clicking on this button will execute the script. Any error messages will be displayed in the console (main menu: Extensions/Console).