Wow, this looks interesting. But before wasting time, can the compiled components also be used in Rhino 5 (Gh0.9)?
// Rolf
Wow, this looks interesting. But before wasting time, can the compiled components also be used in Rhino 5 (Gh0.9)?
// Rolf
“Unfortunately” not.
Hm.
So, is the “Rhino Script Compiler for Rhino5
” project abandoned?
// Rolf
Hi, Giulio. Happy New Year. Thanks for your toturial, that’s very helpful.
But there is a error that troubles me a lot and I can’t figure out why. Here is the code:
from ghpythonlib.componentbase import executingcomponent as component
import Grasshopper, GhPython
import System
import Rhino
import rhinoscriptsyntax as rs
import scriptcontext as sc
class MyComponent(component):
def RunScript(self, crv_id):
sc.doc = Rhino.RhinoDoc.ActiveDoc
crv_o = sc.doc.Objects.Find(crv_id)
a = crv_o.Attributes.Name
sc.doc = ghdoc
return a
Compiling this code follow your tutorial, I got a new GH component without any error. But when I put this component into canvas and loaded input it get red and says:
Solution exception: global name “ghdoc” is not defined.
Do you know why? Can’t run correctly after compiling into GH component. But this code runs OK before the final step.
I have change “ghdoc” into GhPython.DocReplacement.GrasshopperDocument() and solved this problem. I hope I’m not disturbing you.
Hi,Giulio Piacentino.
Is user have to install IronPython to load ghpy files as GH plug-in into Rhino?
And can Rhino5 support ghpy files?
Hi Giulio!
Following your tutorial 1. Compiling a single component in an assembly with the wizard
I have a Runtime error
Thanks in advance!
Hi @piac,
I use this code below often to dynamically add/remove inputs. Is there a way to translate this functionality within the compiled component?
# automnatically set the right input names and types (when using + icon)
numInputs = ghenv.Component.Params.Input.Count
accessList = ghenv.Component.Params.Input[0].Access.list
accessItem = ghenv.Component.Params.Input[0].Access.item
typeFloat = GhPython.Component.NewFloatHint()
typeBool = gh.Parameters.Hints.GH_BooleanHint_CS()
for input in range(numInputs):
access = accessList
typeHint = typeString
if input == 0: inputName = 'width'; access = accessItem; typeHint = typeFloat
elif input == 1: inputName = 'thickness'; access = accessItem; typeHint = typeFloat
elif input == 2: inputName = 'spacing'; access = accessItem; typeHint = typeFloat
elif input == 3: inputName = 'rotation'; access = accessItem; typeHint = typeFloat
elif input == 4: inputName = 'offsetFromWall'; access = accessItem; typeHint = typeFloat
elif input == 5: inputName = 'verticalOrientation' ; access = accessItem; typeHint = typeBool
else: continue
ghenv.Component.Params.Input[input].NickName = inputName
ghenv.Component.Params.Input[input].Name = inputName
ghenv.Component.Params.Input[input].Access = access
ghenv.Component.Params.Input[input].TypeHint = typeHint
ghenv.Component.Attributes.Owner.OnPingDocument()
Hi @sgaray
if you are doing this from an event handler, then it should be fine. Never do this within a solution.
Just keep in mind that you’ll need to use standard Grasshopper input parameters, not Hint-based scripting parameters. Compile a sample component with the Hints that you need, then choose to copy the code. It will show exactly what types are expected.
Giulio
–
Giulio Piacentino
for Robert McNeel & Associates
giulio@mcneel.com