Advanced Python plugin coding for Cinema 4D 

2012-07-12 02:23 发布 | 作品版权归原作者所有,仅供参考学习,禁止商业使用!

288 0 0
Advanced Python plugin coding for Cinema 4D - C4D之家 - title2.32lgm6px71s0w08c8gkk8cwsw.ekdjdxruf9hlgcskw0cwk4c8s.th.jpeg
It’s been a long time… how have you been?
This is going to be another Python/Cinema 4D related post.
While python is great for quickly scripting workflow optimizing tools, prototype stuff or write generators and tags, is it suited for big, complex plugin development?
It is!
You get ‘nearly’ full access to the C++ API of Cinema 4D, don’t have to compile or worry much about platform dependencies, can easily find a ton of neat recipes and libraries out there…
So it’s not only possible to code full-fledged python plugins but it even has its advantages over classical C++ development.
Imagine you wrote a nifty script, decided to make it a simple plugin, and now want to take it a step further – add more features, a complex GUI with some dialogs etc…
If you are still working with the script editor by now, things will most likely start to get out of hand as you introduce more modules and classes, deal with more code and more functionality.
This is the point where you might want to look out for a little help.
We are going to set up an IDE (Integrated Development Environment), talk a bit about modules/packages and finally I will try to give some general hints and tips.

Coding Environment/IDE:Prepare Cinema 4D:
You may skip this part, but I highly recommend it:
  • Make a copy of your Cinema 4D installation – name it “Cinema 4D R12 Dev” for example.
  • Get rid of all Cinema 4D plugins you don’t need for your development
  • Place an empty text file named “c4d_debug.txt” into the root folder of your Cinema 4D copy.
This will slow Cinema 4D down a bit, but enables you to monitor memory leaks.
We will add some useful things on Cinema 4D-side later – for now let’s continue with the Eclipse setup…

Eclipse:
Advanced Python plugin coding for Cinema 4D - C4D之家 - 0.jpg
If you never used one, think of an IDE as your workshop, it’s a collection of tools as well as the place where you do and organize your coding work.
Eclipse is one of the most popular – its Java based, open source, free to use and most importantly has excellent support for python.
So let’s start by downloading and installing Eclipse Classic from http://www.eclipse.org/downloads/
If you don’t have the Java Runtime Environment installed jet, you need to do this first.

PyDev:
As said before, Eclipse has excellent python support – but not out of the box, so we are going to install PyDev.
PyDev will help you coding by adding syntax highlighting, code completion and much more.
Should you encounter any trouble with the following steps, please refer to the PyDev installation manual.
  • After installation, startup Eclipse, click “Help”, and chose “Install New Software…”.
  • Next click the “Add…” button, type in “PyDev” as name and http://pydev.org/updatesas location – then confirm.
  • Now enter “PyDev” in the “Work with:” field, you should see an entry “PyDev for Eclipse” - check it and click“Next”.
After confirming again and accepting the terms, it will download and install.
  • Click “Windows” and open the “Preferences” dialog.
  • Select PyDev and the child “Interpreter – Python”
  • Click “New…”, input “Python Cinema 4D” as name and browse to your Cinema 4D installation.
  • In “/resource/modules/python/res/Python.win64.framework/” select the python.exe.

    Mac: (On OSX the target would be “/resource/modules/python/res/Python.osx.framework/Python” – you may have to execute sudo chmod 777 resource/modules/python/res/Python.osx.framework/Python from the terminal to allow access to the binary)
  • Confirm your selection and the paths PyDev wants to add to your syspath.
So much for the PyDev installation itself, now we have to associate the Cinema 4D Python plugin extension *.pyp with PyDev to enable syntax highlighting and code completion for those files as well:
  • Open ‘Window’ within the file-menu and click ‘Preferences’
  • Select ‘General’ -> ‘Content Types’ from the list on the left.
  • In the ‘Content types:’ view on the right, unfold ‘Text’ and click ‘Python File’
  • Hit the ‘Add…’ button of the ‘File associations:’ list on the lower right, type “*.pyp” into the popup and confirm.
  • Open ‘Window’ and click ‘Preferences’
  • Select ‘PyDev’ -> ‘Editor’ -> ‘Code Style’ -> ‘File Types’ from the list on the left.
  • In the field ‘Valid source files (comma-separated):’ on the right, add , pyp and confirm.
Its helpful to add a file containing all symbols of the Cinema 4D Python API’s “c4d” package to the ‘site-packages folder to spice up the auto-completion – grab it here.
c4d.zip (158.69 KB, 下载次数: 1, 售价: 1 模点)
关闭

C4D精选推荐 上一条 /10 下一条

智能
客服
快速回复 返回顶部 返回列表