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.
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:
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_126.96.36.1991040403\pysrc') import pydevd
And that’s it!
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 the PyDev documentation.
Route the standard- and error output-channels to the PyDev console with…
With the debugging feature added, our Python plugin coding environment should now be complete…
Time to spring into action!