Debugging Cinema 4D Python Plugins with PyDev 

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

397 2 0
Debugging Cinema 4D Python Plugins with PyDev - C4D之家 - debug.ah1weo0164ekcgo0g8c48ck0s.ekdjdxruf9hlgcskw0cwk4c8s.th.jpeg

When hunting down glitches, the debugger is the coder’s weapon of choice…

In the last post about coding advanced Python plugins, this vital part was skipped as Cinema 4D’s Python interpreter doesn’t support it.

But fear not – you don’t have to write countless ‘prints’ or fiddle with python’s inspect module just to fix a simple fence post error.

Stepping through breakpoints and browsing your plugins scope… – all this is possible with the PyDev remote debugger.

How does it work?

The PyDev remote debugger consists of a server running in Eclipse, listening to a given port – and a client (your plugin), that inspects the scope at runtime and sends it to the server.
This concept has the advantage of working with virtually any host-application one can think of – including Cinema4D.

The only disadvantages are that you have to add the client module to your source and to insert a small line of code for each breakpoint.

Setup

As the remote debugger comes with PyDev, it’s already installed within your IDE – we just have to find out where exactly as the installation path varies with the PyDev version:

  • Browse to your Eclipse folder and do a search for a file “pydevd.py”

You should end up with a Path somewhat similar to this:
‘C:\Program Files\eclipse\plugins\org.python.pydev.debug_2.0.0.2011040403\pysrc’

If you find more than one ‘pydevd.py’, make sure you selected the PyDev folder with the latest version number within ‘plugins’.

  • Now open the source file you wish to debug and insert:
    import sys
    sys.path.append('C:\Program Files\eclipse\plugins\org.python.pydev.debug_2.0.0.2011040403\pysrc')
    import pydevd

And that’s it!

Debugging

Let’s do a quick test run and place a breakpoint.

  • Add the line pydevd.settrace() somewhere within your source
  • Switch Eclipse to “Debug View” (upper right) or click ‘Window’ -> ‘Open Perspective’ -> ‘Other’ -> ‘Debug’
  • Start the PyDev remote debug server by clicking the Icon on the top left (the small green bug with the blue ‘P’)
  • Fire up Cinema 4D and switch back to Eclipse

You can now continue or step to other breakpoints by using the small icon bar on the top left or the F5-8 shortcuts.

The variable tab on the right allows you to inspect your plugins scope in detail.

In case this doesn’t work, check your firewall settings first before repeating these steps or taking a look at thePyDev documentation.


Tip: 
Route the standard- and error output-channels to the PyDev console with…

pydevd.settrace(True, True)



With the debugging feature added, our Python plugin coding environment should now be complete…

Time to spring into action! :)

B Color Smilies

Comment :2

相关推荐

百套精美Kitbash3D模型专题合集下载
时尚卡通办公室人物C4D立体图标工程下载Cinema 4D Fashion Cartoon Office Character 3D Icon Project Download
C4D科技新闻片头电视栏目频道包装动画工程下载Cinema 4D Technology News Headline TV Program Channel Packaging Animation Project Download
关闭

C4D精选推荐 /10

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