Okay, I can't promise this is the correct way to do this, but it seems to have worked for me:
Install C4D Py
- Ensure that you have Cinema 4D R20+ installed, I don't think this will work without it.
- In your C4D install directory, unzip the
sdk.zip
file. (Note: this step might not be strictly necessary, not sure.) - Download the latest c4dpy, ensure that it corresponds with your version of C4D.
- You may need to download the latest C4D Service Pack via the Online Updater (
C4D > Help > Check for Updates...
)
- You may need to download the latest C4D Service Pack via the Online Updater (
- Unzip the c4dpy .zip file and copy the contents into your C4D install directory. C4dpy seems to rely on your C4D install's library files and will spit out errors if you don't do this.
Verify the Installation
Mac
Note: I haven't tested on mac, so I'm not sure this works.
Cmd + Space
thenTerminal
- Drag the c4dpy.app file into the terminal - you should get the path to the file.
PC
- Open terminal on Mac or Command Prompt on PC
- Drag the c4dpy.exe file into the Command Prompt
Both
- Press enter/return
- You should see something like:
C:\Users\donovan>"C:\Program Files\MAXON\Cinema 4D R20\c4dpy.exe"
Welcome to the world of C4D and Python 2.7.14 (default, May 3 2018, 18:05:57) [MSC v.1500 64 bit (AMD64)] (c) 2018
Setup your IDE
Instructions will vary a bit on a per IDE basis.
Create a test script (All IDEs)
- Open C4D
- Script > Script Manager
- Script Manager > File > New.... You should see something like:
import c4d
from c4d import gui
# Welcome to the world of Python
# Script state in the menu or the command palette
# Return True or c4d.CMD_ENABLED to enable, False or 0 to disable
# Alternatively return c4d.CMD_ENABLED|c4d.CMD_VALUE to enable and check/mark
#def state():
# return True
# Main function
def main():
gui.MessageDialog('Hello World!')
# Execute main()
if __name__=='__main__':
main()
- Script Manager > File > Save...
- Save the script as
helloworld.py
. - Open your scripts folder: C4D > Script > User Scripts > Script Folder...
- Open the
helloworld.py
in your IDE.
PyCharm
Configure your Intepreter
Additional C4D Py Prep
- PyCharm requires that Python Interpreters be named
python.exe
so rename thec4dpy.exe
file in your C4D Directory topython.exe
. (Note: I'm not sure if this breaks any of C4D Python's functionality).
In PyCharm
- File > Settings > Project > Interpreter
- Click on the Project Interpreter dropdown (probably says Python 2.7) and select "Show All".
- Click on the
+
to add a new interpreter. - Click on
System Interpreter
- Browse to the location of the renamed
c4dpy.exe
(now calledpython.exe
). - Choose
OK
. It will probably take a minute for the Interpreters list to update to include the c4dpy interpreter. - Choose
OK
to select thePython 2.7 (1)
interpreter (Or however your renamed c4dpy.exe interpreter is listed). - In the text editor type
from c4d import
then hitctrl + space
trigger auto-complete.- You may see a status update about "Updating skeletons" this can take a few minutes the first time as PyCharm has to build up a map of the C4D sdk (<- I think that's what it's doing, not certain).
- Eventually, you should see something like:
Congratulations, you've now got AutoComplete working in PyCharm!
Microsoft VS Code
Prerequisites
If you can't get IntelliSense (autocomplete) working with a default Python install, it's probably not going to work with a C4D Py. If you can do the following, you're in good shape to work with C4D Py in VS Code.
- Install the Python VS Code Extension
- Follow the VS Code Python Tutorial.
Configure VS Code
- Open VS Code
- File > Open Folder > ... Navigate to your C4D Scripts folder (You can use C4D > Scripts > User Scripts > Scripts Folder... to easily find it).
Ctrl + Shift + P
to search for : "workspace settings" (Note: this setting is only being adjusted for this folder).
- In the worspace settings panel...
- Start typing
python.pythonPath
then hit enter
{
"python.pythonPath": "python"
}
- Set the python path to the location of your
c4dpy.exe
file.
{
"python.pythonPath": "C:\Program Files\MAXON\Cinema 4D R20\c4dpy.exe"
}
Windows paths use a \
which needs to be escaped \\
or reversed /
for the path to properly register in the VSCode Settings.
{
"python.pythonPath": "C:/Program Files/MAXON/Cinema 4D R20/c4dpy.exe"
}
- File > Save Workspace (This will ensure the settings get remembered.
- Restart VS Code
- In
helloworld.py
inmain():
typegui.
and then pressctrl + space
. You'll see:
- Wait a minute as VS code builds up its understanding of C4D's API, eventually, you should see:
Congratulations, you've now got AutoComplete working in VS Code!
To the C4D Devs: If these instructions are accurate, and you haven't alread written something similar, feel free to include it in the SDK / C4D Py Docs.
-- Edits --
2018/09/05 10:27 - Added screenshot to clarify that you should copy the contents of the Unzipped file to your C4D directory.
2018/09/04 15:50 - Added instructions for VS Code.