標籤:

Use 3rd-party IDE to edit GHPython code

Aim:

1, to use 3rd-party IDE (like Pycharm, which is my choice in this article) to modify GHPython code on Grasshopper canvas and any modification on code in IDE will be updated in real time in GHPython interpreter in Rhino Platform. Also Pycharm can greatly helps me do source control, version control and git.

2, Grasshopper built-in IDE is reaaaaally ugly, font and text size cannot be changed, not to mention better coding experience in Pycharm!

Let me be clear:

This is a passage of little help to most of the people. Also if you often need the hint given in HELP column in GHPython IDE, dont use 3-rd-party IDE, since the hint is likely to be crippled in like Pycharm, see pics below for more details. And IronPython doesnt support great number of packages in grasshopper like numpy Tensorflow etc. , which Pycharm cannot help(not to my knowledge). If you want to do so, ehhhhh sorry I dont know. Consider communication between Python3 and IronPython. Ill try later, if I want to.

And also Ill jump over details, since it is not a passage for amateurs.

Ok lets get started.

First of all we should know .NET IronPython is the interpreter used in Rhino platform, so first of all set Pycharm interpreter to be IronPython. Manually install if necessary.

Next. Python PATH. Copy what I have done in the pic

test test test:

Ok working now. Ignore the warning since the var surface_imported is defined in Grasshopper

Limited hint given, but perfect code completion!

Code completion is now working. Remember to disable code case sensitive for better code completion

Final sample code:

import rhinoscriptsyntax as rs
import Rhino
import Rhino.Geometry as rg

print("Hello World and fuck C sharp!")

surface_imported = surface_imported
new_surface = rs.UnrollSurface(surface_imported)
point1 = rg.Point3d(1,2,3)

Ok back to Grasshopper canvas, still copy what I have done in the pic. Locate project.

Ok working now. The obvious bug in the pic is what I cannot solve, but seems culling null is working so Im choosing to ignore. Should be Grasshopper bug.

So the code that we have written in Pycharm is running in Grasshopper!

Do source control via git if you like!

Enjoy!

CREDIT:

discourse.mcneel.com/t/

PS. According to Giulio Piacentino, adding code as follows is useful, but I find no difference. Worth a try if weird bug emerges.

import clr
clr.AddReference("RhinoCommon")
import Rhino
import Rhino.Geometry
// select "Create skeleton implementation for binary import" in Pycharm

推薦閱讀:

TAG:Rhino | PyCharm |