I would like to introduce the new GhPython compiler feature we are developing for Rhino in Serengeti.
This is an early build, and it is the first time this is shown to the public, so some “rough edges” might still be there. Keep that into account.
You are encouraged to write comments below here. I am also posting a example below here.
Step by step example
A component that shows a textdot relative to screen position (“billboard”).
1 We begin with a customary GhPython component. Please note that these features are only available in Seregeti right now.
We can add and remove inputs by zooming in and out, and change the input names as usual.
2 We put together a small definition for testing the script. We can override the icon by drag-and-dropping 24x24 png’s.
3 We switch to component compilation mode. This mode allows to write a full class that represents the object that runs the script. This follows the Grasshopper SDK IGH_Component interface, but is technically not exactly it.
4 The component code is replaced with a longer version, similar to this one:
5 We need to type the full code. In this case:
from ghpythonlib.componentbase import executingcomponent as component import Grasshopper, GhPython import System import Rhino import rhinoscriptsyntax as rs class MyComponent(component): def __init__(self): super(MyComponent,self).__init__() self.x = "" self.L = Rhino.Geometry.Point2d(0,0) def RunScript(self, x, L): self.x = str(x) if L is not None: self.L = Rhino.Geometry.Point2d(L.X, 1000-L.Y) def DrawViewportWires(self, args): try: args.Display.DrawDot(self.L.X, self.L.Y, self.x, System.Drawing.Color.Black, System.Drawing.Color.White) except Exception, e: System.Windows.Forms.MessageBox.Show(str(e), "script error") def get_ClippingBox(self): return Rhino.Geometry.BoundingBox()
Our definition is ready.
We hit “Compile” and fill the form.
We just need to save the .GHPY to the default folder, and Grasshopper will load it automatically.
If you want, you can also export the compilable code and compile it yourself with this short code:
import clr clr.CompileModules("result.ghpy", "myuniquemodule1.py", "myuniquemodule2.py", ...)
Only one gotcha (automatically taken care of in the default “Compile…”): your modules need to have unique names, otherwise a non-unique module might shadow another one.
Please let me hear your thoughts and comments.
for Robert McNeel & Associates