Hi,
I’m looking into debugging GhPython scripts in Visual Studio. This works, except problems in identifying the file that holds the executed script. The problems are expected as GhPython does not get a file name and then execute that file, but rather it gets a string and when executing this script the debugger has not way to get information on the file containing the script. Visual Studio reports a ‘Source not available, frame not in module’ error and debugging is not really possible.
I see two ways to fix this: manually specify the file (that possible in Eclipse, VS does not seem to offer this possibility) or fix GhPyhton.
The later seems to be easy at first glance, as the PythonScript class offers a ExecuteFile() metod. If I execute a script using this method the debugger can identify the file. But I don’t see a way to get access to the GhPython inputs and outputs? PythonScrip provides the necessary methods to setup the scope for the script properly, but ExecuteFile() does not run the script in that scope (this probably makes sense usually, but not here).
So, and ideas to resolve the issue?
See you
Flo
PS: A workaround is to write a small GhPython script that imports the script to be debugged but I find that not very elegant.
I tested it, and it works, VS or ptvsd identifies the stack frame and file correctly if ExecuteFile is used. The only problem is, that a variable created by PythonScript.SetVariable() is not available in the executed script. Or at least I did not make to get this to work, it works fine, however, if I use the ExecuteScript method to run a script, but than VS can’t identify the file.
probably this Tuesday*, a new GhPython version will ship with Rhino 7 WIP. It will include a new execution mode meant for debugging. The specs of the bugfix are on report RH-53391.
In place of code, you will now be able to run both absolute files and files specified as relative to the Grasshopper definition. These files are run with ExecuteFile, which may or may not run as fast as with compiled memory code, but might help with debugging.
Thanks,
Giulio
–
Giulio Piacentino
for Robert McNeel & Associates giulio@mcneel.com
Hi Giulio,
that sounds great. That is exactly what I treid to add to GhPuthon, but I failed at giving the external script access to the Grasshopper input and output variables. I’ll wait and test the new version as soon as it’s available.
Hi Dan,
I tested GhPython in WIP 7.0.19176.14015 (06/25/2019) and indeed the ‘Input is path’ option is present and I’m able to execute a script, but how do I get access to the input and output variables?
The embedded script works as expected, it can access the input ‘myStr’.
The script streamt from a file in the old way works as expected.
The script given by filename in the new way does is executed, but not have access to the GhPython inputs and outputs.
If you really find the time to work on the problem, could you briefly explain how you solved it? I’d be interested because right no I do not see a nice solution.
One quick fix of course is to load the file and use the ExecuteScript to execute the script, but that would not solve the debugging issue.
The only thing I can think of is to use ExecuteScript to execute something like this:
Hi Giulio,
I tested the latest WIP version and it work as expected now. This is a really nice feature as it allows to edit and debug GhPython scripts in an external IDE. I’m using Visual Studio 2019 but, VS Code, Eclipse or any other IDE would work just as fine.
Any chance you guys could collaborate on a step by step guide to setting things up to edit and debug GhPython scripts in Visual Studio? Great if it could end up in the Developer docs, too. I’ve read through this thread and looked elsewhere: the info may all be there, but if it is, it’s scattered and hiding from me!
Any chance you guys could collaborate on a step by step guide to setting things up to edit and debug GhPython scripts in Visual Studio?
Sure, I already had two requests buy other people, and I started working on a detailed step by step guide, but I did not find the time to finish it. But it’s still on my to do list.