I am thinking about writing the Grasshopper Python codes in Visual Studio or Visual Studio Code. Is there a way to do that?
I know you can have a connection between Rhino and Visual Studio Code but not with the Grasshopper Python per my knowledge. Please let me know if there is anyone who can shed some light on it. Would appreciate that. Thanks!
As far as I know, there is no good solution for this right now. What I sometimes do is reading code saved in external files using the “code” input of ghpython components. You don’t have any code completion then, but can use version controls systems and use editor features like code formatting then.
So you could develop in the gh component and then move to an external .py file.
Thank you for the relpy Martin. Let me try what you have just said but I am pretty I will struggle to figure that out as I never had the chance to explore this part. Hopefully will come across some other methods as well.
You can then import your module inside your ghPython script component and use it by just setting up some interfacing functions you prepare to feed in GH inputs etc. If you make changes to your module code and want to update / hotswap it once it has been loaded in your current Rhino session, you can use built in module reload function.
For writing standalone Grasshopper Python scripts in Visual Studio Code, relevant answers can be found here and here.
However, when it comes to developing a full Grasshopper plugin with multiple Python components in Visual Studio, similar to the official Grasshopper C# template, the options have been limited—until now.
I recently released two open-source solutions that address this challenge:
PythonConnectedGrasshopperTemplate – Built on PythonConnect, this solution was originally developed in 2021 for Rhino 6, when IronPython was still limited to Python 2. It enables C# components to execute Python 3 scripts asynchronously in a parallel Python process, and was used to develop the early versions of Muscle, a Grasshopper plugin for the structural engineering field.