{"id":1261,"date":"2011-05-29T12:53:32","date_gmt":"2011-05-29T10:53:32","guid":{"rendered":"http:\/\/www.smart-page.net\/blog\/?p=1261"},"modified":"2011-05-29T13:10:47","modified_gmt":"2011-05-29T11:10:47","slug":"debugging-cinema-4d-python-plugins-with-pydev","status":"publish","type":"post","link":"http:\/\/www.smart-page.net\/blog\/2011\/05\/29\/debugging-cinema-4d-python-plugins-with-pydev\/","title":{"rendered":"Debugging Cinema 4D Python Plugins with PyDev"},"content":{"rendered":"<p>When hunting down glitches, the debugger is the coder&#8217;s weapon of choice&#8230;<\/p>\n<p>In the last post about <a href=\"http:\/\/www.smart-page.net\/blog\/2011\/05\/09\/advanced-python-plugin-coding-for-cinema-4d\/\" target=\"_blank\">coding advanced Python plugins<\/a>, this vital part was skipped as Cinema 4D&#8217;s Python interpreter doesn&#8217;t support it.<\/p>\n<p>But fear not &#8211; you don&#8217;t have to write countless &#8216;prints&#8217; or fiddle with python&#8217;s inspect module just to fix a simple fence post error.<\/p>\n<p>Stepping through breakpoints and browsing your plugins scope&#8230; &#8211; all this is possible with the PyDev remote debugger.<\/p>\n<p><!--more--><\/p>\n<h1>How does it work?<\/h1>\n<p><img decoding=\"async\" loading=\"lazy\" class=\"alignnone size-full wp-image-1262\" title=\"debug2\" src=\"http:\/\/www.smart-page.net\/blog\/wp-content\/uploads\/2011\/05\/debug2.jpg\" alt=\"\" width=\"683\" height=\"88\" srcset=\"http:\/\/www.smart-page.net\/blog\/wp-content\/uploads\/2011\/05\/debug2.jpg 683w, http:\/\/www.smart-page.net\/blog\/wp-content\/uploads\/2011\/05\/debug2-300x38.jpg 300w\" sizes=\"(max-width: 683px) 100vw, 683px\" \/><\/p>\n<p>The PyDev remote debugger consists of a server running in Eclipse, listening to a given port &#8211; and a client (your plugin), that inspects the scope at runtime and sends it to the server.<br \/>\nThis concept has the advantage of working with virtually any host-application one can think of &#8211; including Cinema4D.<\/p>\n<p>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.<\/p>\n<h1>Setup<\/h1>\n<p><img decoding=\"async\" loading=\"lazy\" class=\"alignnone size-full wp-image-1265\" title=\"debug4\" src=\"http:\/\/www.smart-page.net\/blog\/wp-content\/uploads\/2011\/05\/debug4.jpg\" alt=\"\" width=\"683\" height=\"79\" srcset=\"http:\/\/www.smart-page.net\/blog\/wp-content\/uploads\/2011\/05\/debug4.jpg 683w, http:\/\/www.smart-page.net\/blog\/wp-content\/uploads\/2011\/05\/debug4-300x34.jpg 300w\" sizes=\"(max-width: 683px) 100vw, 683px\" \/><\/p>\n<p>As the remote debugger comes with PyDev, it&#8217;s already installed within your IDE &#8211; we just have to find out where exactly as the installation path varies with the PyDev version:<\/p>\n<ul>\n<li>Browse to your Eclipse folder and do a search for a file &#8220;pydevd.py&#8221;<\/li>\n<\/ul>\n<p>You should end up with a Path somewhat similar to this:<br \/>\n<em>&#8216;C:\\Program Files\\eclipse\\plugins\\org.python.pydev.debug_2.0.0.2011040403\\pysrc&#8217;<\/em><\/p>\n<p>If you find more than one &#8216;pydevd.py&#8217;, make sure you selected the PyDev folder with the latest version number within &#8216;plugins&#8217;.<\/p>\n<ul>\n<li> Now open the source file you wish to debug and insert:\n<pre>import sys\r\nsys.path.append('C:\\Program Files\\eclipse\\plugins\\org.python.pydev.debug_2.0.0.2011040403\\pysrc')\r\nimport pydevd<\/pre>\n<\/li>\n<\/ul>\n<p>And that&#8217;s it!<\/p>\n<h1>Debugging<\/h1>\n<p><img decoding=\"async\" loading=\"lazy\" class=\"alignnone size-full wp-image-1263\" title=\"debug3\" src=\"http:\/\/www.smart-page.net\/blog\/wp-content\/uploads\/2011\/05\/debug3.jpg\" alt=\"\" width=\"683\" height=\"79\" srcset=\"http:\/\/www.smart-page.net\/blog\/wp-content\/uploads\/2011\/05\/debug3.jpg 683w, http:\/\/www.smart-page.net\/blog\/wp-content\/uploads\/2011\/05\/debug3-300x34.jpg 300w\" sizes=\"(max-width: 683px) 100vw, 683px\" \/><\/p>\n<p>Let&#8217;s do a quick test run and place a breakpoint.<\/p>\n<ul>\n<li>Add the line pydevd.settrace() somewhere within your source<\/li>\n<li>Switch Eclipse to &#8220;Debug View&#8221; (upper right) or click &#8216;Window&#8217; -&gt; &#8216;Open Perspective&#8217; -&gt; &#8216;Other&#8217; -&gt; &#8216;Debug&#8217;<\/li>\n<li>Start the PyDev remote debug server by clicking the Icon on the top left (the small green bug with the blue &#8216;P&#8217;)<\/li>\n<li>Fire up Cinema 4D and switch back to Eclipse<\/li>\n<\/ul>\n<p>You can now continue or step to other breakpoints by using the small icon bar on the top left or the F5-8 shortcuts.<\/p>\n<p>The variable tab on the right allows you to inspect your plugins scope in detail.<\/p>\n<p>In case this doesn&#8217;t work, check your firewall settings first before repeating these steps or taking a look at the <a href=\"http:\/\/pydev.org\/manual_adv_remote_debugger.html\" target=\"_blank\">PyDev documentation<\/a>.<br \/>\n<br \/>\n<strong><span style=\"color: #ff6600;\">Tip: <\/span><\/strong><br \/>\nRoute the standard- and error output-channels to the PyDev console with&#8230;<\/p>\n<pre>pydevd.settrace(True, True)\r\n<\/pre>\n<p>\nWith the debugging feature added, our Python plugin coding environment should now be complete&#8230;<\/p>\n<p>Time to spring into action! \ud83d\ude42<\/p>\n","protected":false},"excerpt":{"rendered":"<p>When hunting down glitches, the debugger is the coder&#8217;s weapon of choice&#8230; In the last post about coding advanced Python plugins, this vital part was skipped as Cinema 4D&#8217;s Python interpreter doesn&#8217;t support it. But fear not &#8211; you don&#8217;t have to write countless &#8216;prints&#8217; or fiddle with python&#8217;s inspect module just to fix a simple fence post error. Stepping through breakpoints and browsing your &hellip; <a href=\"http:\/\/www.smart-page.net\/blog\/2011\/05\/29\/debugging-cinema-4d-python-plugins-with-pydev\/\" class=\"more-link\">Continue reading <span class=\"screen-reader-text\">Debugging Cinema 4D Python Plugins with PyDev<\/span> <span class=\"meta-nav\">&raquo;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[52,53,88],"tags":[183,180,179,181],"_links":{"self":[{"href":"http:\/\/www.smart-page.net\/blog\/wp-json\/wp\/v2\/posts\/1261"}],"collection":[{"href":"http:\/\/www.smart-page.net\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.smart-page.net\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.smart-page.net\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/www.smart-page.net\/blog\/wp-json\/wp\/v2\/comments?post=1261"}],"version-history":[{"count":14,"href":"http:\/\/www.smart-page.net\/blog\/wp-json\/wp\/v2\/posts\/1261\/revisions"}],"predecessor-version":[{"id":1280,"href":"http:\/\/www.smart-page.net\/blog\/wp-json\/wp\/v2\/posts\/1261\/revisions\/1280"}],"wp:attachment":[{"href":"http:\/\/www.smart-page.net\/blog\/wp-json\/wp\/v2\/media?parent=1261"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.smart-page.net\/blog\/wp-json\/wp\/v2\/categories?post=1261"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.smart-page.net\/blog\/wp-json\/wp\/v2\/tags?post=1261"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}