I’m a bit confused regarding debugging possibilities:
The integrated rhino.Python script editor provides a debugger. Is there a way to use an external debugger. I’d like to use PyDev not only as an editor but also make use of the integrated debugger.
Is using the .NET SDK or the C++ SDK the only way to get a full featured IDE for writing Rhino scripts/plugins?
I did some tests using the PyDev remote debugger system (server run by PyDev, evoked by the script ). It turns out that this works fine using the CPython interpreter, but not Rhinos integrated IronPython. The IronPython build used by Rhino does not support _getframe. This can usually be enabled by the command line parameter -X:Frame, but, of course, these is no way to do so in Rhino.
So, looks like there’s not remote debugging for RhinoPython, right?
Could the included IronPython build be change to support _getfame in a future release?
 import pydevd; pydevd.settrace(port=678)
You can enable frames in Rhino by running ‘editpythonscript’ and checking the option in the options dialog that can be accessed by the editor. This is a sticky setting, so no matter what editor you are using the frames will be turned on.
I’m interested to hear what you find from your tests. I looked into adding remote debugging support a long time ago and never really got anywhere with that project.
Oh, thanks for pointing me to the ‘Enable Frames’ option. I tried warping systems frames to get _getframe by using this module, but I wasn’t successful.
Now I switched on frames and pydevd works.
Now I can write and debug a Rhino.Python script in Eclipse/PyDev.
Only two things a necessary:
Add the path to the pydevd library. pydevd is located in /eclipse/plugins/org.python.pydev_[version]/pysrc/.
Import pydevd and start the debug client at the point the debugging session should start in the script to be debugged:
import pydevd; pydevd.settrace(port=678)
I didn’t do any in depth testes, but it seams to work just fine. Thanks.
Great! Could you provide some more instructions on how you did this? I’m not very fluent with pydev, but would love to be able to show this feature to other people.
I tried to write a tutorial:
Remote Debugging Rhino.Python Scripts
Please let me know if theres something I can improve.
A brief update:
The whole thing does also work for a Python script inside the GhPython Gasshopper component, though break points do not work properly, but inspection and step into/over/… do work as expected.
GyPython is an open source Gasshopper component, the allows to include Python script in Grashopper definitions.
The source code is on GitHub: https://github.com/mcneel/ghpython/, a precompiled version is also on GitHub: https://github.com/mcneel/ghpython/downloads/
Thanks for writing this. I really need to set aside some time to try this since it would be really useful for a lot of people to know about.
I’ve followed Steve Baer tutorial about how to set-up eclipse to write rhinopython code (Rhinocommon and rhinoscriptsyntax) and now I’m setting-up Eclipse to debug code from ghPython and Rhino python editor.
I can debug perfectly python code from the Rhino script editor, but when I debug from Grasshopper, everything works, but I cannot see the code written in the GH component in the eclipse window, neither activate breakpoints into the code. Is there any way to specify to pydevd what code it should run and analyse from GH? I was thinking that could be possible to reference the python code from an external file into the ghpython component and tell pydevd that he have to use that file to debug.
Thanks in advance.
PS.: This is what I have debugging code used in GH component.
Ok guys SOLVED!
I established without knowing it a path to make pydevd look for source code. Removing the path now pydevd ask me to choose the code that I want to debug.
@piac and @alain you may be interested in seeing this post
good to here you figured it out. Sorry that my tutorial didn’t make clear hat its necessary to import pydevd.
Nice tutorial, I’ll link to it from mine.
Yes, I read Angel’s nice tutorial yesterday evening. It’s inspiring to see a new creative use for the code input parameter.
for Robert McNeel & Associates
The question I have is - what about linking the “native” EditPythonScript editor to the GH Python component in a similar fashion - and hopefully simpler to set up - wish for V6…
(Or, I guess the full editor/debugger running inside the component would be even better…)
Thanks @piac! I’m glad you like it (adding you to the credits :P)
You are totally right @Helvetosaur, the process is a little bit tedious if you don’t have to edit long scripts inside ghPython component, but when you need it, there is not a lot of choices to pick from.
I totally agree with you @Helvetosaur , probably a seamless integration between editors is a nice way to go, but I have some suggestions if this happen, because the rhino.python editor is neither a perfect solution (no proper autocomplete, no linter, no proper outliner…)
Everytime I think about a perfect lightweight code editor, SublimeText comes to my mind: reliable, fast, lot of options to personalize your workflow ( custom code snippets, multiline selection, error linter via plugins, powerful autocomplete python API to create your extensions…) , and code edition tasks…it lacks of proper debugging options but the rest is just perfect to take as example of a good and lightweight code editor.
The autocomplete for all rhinoscriptsyntax and RhinoCommom related stuff plus imported modules is pretty good IMO… I think the current editor is not bad for most “average” tasks and programming skills, at least at my level of operation, I don’t feel limited by it. I would like to see some additional features, though - most importantly code snippets as you mentioned…
Yep! That’s true. What I mean by proper autocomplete is that it doesn’t track your code to offer you variables that you created before, functions or classes created in the document, etc…That stuff speed up the process of writting code a lot. That is because I said “proper” instead of “lack of”.
Yep, you’re right about that! --Mitch