SendPythonCodeToCinema4D is a plugin for Cinema 4D that allows you to sent python script code to Cinema 4D and execute it. Plug-in based on Niklas Rosenstein's Remote Code Runner. Get it here.
Download the latest code from GitHub and unpack the content into your Cinema 4D plugin directory.
```
Cinema 4D RXX/
plugins/
SendPythonCodeToCinema4D/
SendPythonCodeToCinema4D.pyp
send_python_code.py
```
Use command line to send python script code to Cinema 4D:
cmd python -u "d:\Your Cinema 4D Plugins\SendPythonCode\send_python_code.py" --file "c:\\script.py"
or use full path to python executable:
cmd "c:\Python27\python.exe" -u "d:\Your Cinema 4D Plugins\SendPythonCode\send_python_code.py" --file "c:\\script.py"
By default the client now scans the port range and discovers the active Cinema 4D plugin by a lightweight handshake before sending code.
You can use SendPythonCodeToCinema4D with different code editors like a Notepad++, Sublime Text or PyCharm.
python -u "d:\Your Cinema 4D Plugins\SendPythonCode\send_python_code.py" --file "$(FULL_CURRENT_PATH)" --origin "Notepad++"
Setup run-command name and press Save. Now you can send code from opened for editing python script file to Cinema 4D. Also using Notepad++ NppExec plug-in you can send to Cinema 4D unsaved code. Install NppExec plug-in, open menu Plugins > NppExec > Execute and enter this code:
set TEMP_PATH = $(NPP_DIRECTORY)\temp_script.py
text_saveto "$(TEMP_PATH)"
python -u "d:\Your Cinema 4D Plugins\SendPythonCode\send_python_code.py" --file "$(TEMP_PATH)" --origin "Notepad++"
Open Tools > Build System > New Build system. Paste this code:
{
"cmd": ["python", "-u", "d:\\Your Cinema 4D Plugins\\SendPythonCode\\send_python_code.py", "--file", "$file", "--origin","Sublime Text"],
"selector": "source.python",
"file_regex": "^\\s*File \"(...*?)\", line ([0-9]*)"
}Save file with desired name. Then go to Tools > Build System and select already created Build system. To send code to Cinema 4D use command Tools > Build. Also for more convienient use you can setup shortkey.
Go to menu File > Settings > Tools > External Tools.
Setup Tool settings like this:
Name: SendCodeToC4D
Description: Send python code to Cinema 4D from PyCharm
Program: python (or c:\Python27\python.exe)
Arguments: -u "d:\Your Cinema 4D Plugins\SendPythonCode\send_python_code.py" --file $FilePath$ --origin PyCharm
Working directory: $FileDir$
To send code to Cinema 4D use command Tools > External tools > SendCodeToC4D. Also for more convienient use you can setup shortkey.
When Cinema 4D starts, the plugin first tries the preferred port and if it is busy it scans the next ports in range until it finds a free one.
- Default port range:
2900-2910 - The plugin binds the first free port in that range.
- The client scans the same range and sends a lightweight
pinghandshake until it finds the live plugin. - If you want a single fixed port, pass the same value to
--portand--port-end.
You can override plugin defaults with environment variables:
SENDPYCODE_C4D_PORT_STARTsets the preferred starting port for the plugin.SENDPYCODE_C4D_PORT_ENDsets the last port included in the scan range.
Client options:
--portsets the scan start port.--port-endsets the scan end port.--connect-timeoutsets the per-port timeout used during discovery.
The plugin now returns structured execution results back to the client.
- Successful runs can print
stdoutback to your editor or terminal. - Python exceptions from Cinema 4D are returned in
stderr. - Discovery now relies on the plugin handshake, so the updated client is intended to be used together with the updated plugin.
You can use SendPythonCodeToCinema4D also for editing Cinema 4D Python objects like a Python Generator, Python Effector, Python Tag and Python Field. For that use script code docstring:
To change code in Python generator use in docstring:
Generator: <Your python generator object name>To change code in Python effector use in docstring:
Effector: <Your python effector object name>To change code in Python tag use in docstring:
Tag: <Your python tag name>To change code in Python field use in docstring:
Field: <Your python field object name>After sending this code to scene all Python field objects with name "Python Field" will recive it.
"""
Python Field description
Author : Mike Udin
Web-site : mikeudin.net
Field : Python Field
"""
import c4d
def main():
# code here
pass
