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:
- Double-click on a word to select it (keep the mouse button pressed to select additional text).
- Clicking on a line number will select the entire line (keep the mouse button pressed and drag vertically to select additional lines).
- When valid characters are typed (quotation marks, brackets, etc.), these will automatically be created double with the cursor positioned correctly so you can continue typing without having to worry about closing the bracket. The same applies to selected text: typing a respective character will close the text block with the symbols mentioned above.
- Highlighted text will be commented out when * (asterix) is entered.
- Highlighted text can be moved with the mouse (while simultaneously pressing the Cmd/Ctrl key), whereby the cursor will display the text's new position.
- Undo/redo can be used on text.
- A colored marker will be displayed between text and line number. The colors have the following meaning: yellow (new); green (compied); blue (saved but not compiled). This color coding only works for newly entered text. As soon as the file has been saved, this color coding will no longer be displayed.
File Menu
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).
Use this command to load non-write protected (non-encrypted) Python codes (*.py). The file selection dialog will jump directly to the proper directory.
Use this command to import code into the Script Manager. The following file formats can be imported:
*.py (Python)
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.
All new or modified scripts will be saved.
The script currently selected under Script will be deleted after a security prompt is confirmed by you.
Duplicates the script currently selected under Script.
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.
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.
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
Changes made to the code can be undone or redone.
Cuts out the selected code and copies it to the cache.
Copies the selected code to the cache.
Pastes the cut or copied code from the cache to the selected location.
Deletes the selected code.
Selects or deselects all selected code. The code can also be deselected by clicking anywhere within the code window.
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.
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.
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.
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).