For our teaching course AR-327 here at EPFL we developed for our students a tiny Rhino plug-in to run C# and Python scripts (both CPython and IronPython) from VSCode directly into Rhino.
We loved the new editor in V8 and we are super grateful to have it but we also let our students experience an external IDE with all its advantages, notably AI-assisted coding (Copilot, Bito, Tabnine, etc). There were few VSCode-Rhino connectors but they couldn’t run C# and CPython, nevertheless they’ve been a great source of inspiration. Anyhow, here’s a simplified version: script-sync .
We made it free and open. Hope it might be useful to someone! Cheers🌲
In case I just put it out there a pre-release of script-sync to make script-sync work in grasshopper (for Pyrhon3)! You can run and edit multiple Python3 scripts with the script-sync component in grasshopper:
To test it update the yak manager and the vscode extension to v1_1_0!
Hope it can be useful to someone and if there any problems or for feature requests do not hesitate to open an issue in the github repo.
I’d like to have contextual help when I use the ‘rhinoscriptsyntax’ class … as inside the GH, for example writing ‘import rhinoscriptsyntax as rs’ and ‘rs.contou’ GH suggest to me all methods containing ‘contou’ as name
Davide
you talking about the autocomplete and the intellisense for vscode in this case. Script-sync does not install it automatically for you but you can try to install the Python Stubs, check it out.
Hello @eirannejad, thanks for passing by ! Indeed, for Rhino is as simple as ScriptEditor Run but for gh it’s not so straightforward since I tried to use exec.
Now, how to integrate IronPython and C# in gh and vscode is not very clear to me. But if you have any idea how this or anything else in script-sync could be improoved or extended I would love to know
I took a different route some years ago. You can compile IronPython and C# code directly into memory. This process is completely different for Rh8 (Net7) and Rh5-7 (Net 4.8) . For modern Net you should use the Roslyn compiler and directly compile for memory. Ideally loading the compiled code in a dedicated AssemblyLoadContext. For older Net you see an example for RH and GH in this thread:
Btw, in an application I develop, I use the Windows specific “FileSystemWatcher” for synchronising Text files in different code editors. Therefore no server/client communication is required, although a VSExtension is much neater!
I must admit, I have not used Rhino 8 yet, although I followed many discussions. Technically IronPython is written in C# and should be compiled the same way, just as C# code would do. The Roslyn compiler is a complete rewrite of the CSharpCodeProvider in NET, and in my applications (not related to Rhino), it was quite an effort to migrate from NET 4.8 to Core 3.1 by the time. One of these applications supports scripting, and I was using Roslyn to compile those scripts. So its is not so difficult for C#, but I would also not expect IronPython to be this complicated. But I have no idea if Rhino8 running on NET7 is even supporting IronPython. The problem with IronPython is that its quite a niché technology, with limited documentation…
For simple scripts you can just point the Grasshopper component to the script file and activate the sync option on the script input parameter. This will recompute the definition when the script changed. As of this moment SDK-Mode (ScriptInstance) is not supported on input scripts though.
I know and this is already great for simple scripts in grasshopper! But when working with multiple modules or leave alone when you develop pypi packages the script component falls a tiny short.
This is the kind of functionality we added in #script-sync, like so:
Would love to see it integrated it one day (also for C#)!
How can I import rhino/GH libraries into a python project? I see above the stubs can be installed, but I can’t figure out how to import, for example, rhinoscriptsyntax into my project? Is there a how-to on this somewhere?
Not confirmed yet but I could look into it in september. If you want you can open an issue here as a feature request and we’ll do our best to integrate it in the road map!
I have just been experimenting with scriptsync the past couple of days and it does seem very interesting!
I do have an error when returning an output that is a datatree though.
I tend to create a variable test_output that I use for a sort of visual debugging when working on geometry algorithms and I use treehelper at the end of my script to convert what may be nested lists to a datatree for gh.
Actually script-sync is already automatically parsing lists for you your python when you return them. No need to use (the amazing) ghpythonlib.treehelpers. To try out just return a simple list, it will be parsed into a ghtree with one branch.
Here is where this happens in the code of script-sync if you are interested:
Now the problem is that for now script-sync is not supporting the convertion of nested list as GhTree. Hence when you return a tree it will fail.
I can actually try to implement a detector that recognize if what you return in your code is already a tree object (and also add an automatic parser for the nested lists into GHTrees). I’ll pop a message when it is done, I marked it as an issue here.