algorithmic modeling for Rhino
how is this development going? If you still need some help, could you please start a new discussion? (this one is a bit old)
it's a bit of code, but here is how you can do it. This sets a circle into Grasshopper and receives the result. Save the file on the desktop to test this. In the EditPythonScript editor:
import clr clr.AddReferenceByName("Grasshopper")
from Rhino import RhinoApp, RhinoDoc
from Rhino.Geometry import *
gh = RhinoApp.GetPlugInObject("Grasshopper")
docServer = Grasshopper.GH_InstanceServer.DocumentServer
doc = docServer # first opened document
def FindBatteryByNickname(docObjects, name):
if docObjects is None: return None
for obj in docObjects:
attr = obj.Attributes
if attr.PathName == name:
raise Exception(name + " was not found in document")
param = FindBatteryByNickname(doc.Objects, "myBegin")
if param is not None:
newCircle = Circle(Point3d(1,11,111), 32)
param.AddPersistentData(newCircle) # you must add the right type here!
param.ExpireSolution(True) # recomputes the whole solution
param = FindBatteryByNickname(doc.Objects, "myResult")
if param is not None:
ghCircles = param.VolatileData # access persistent data as a tree
ghCircle = ghCircles # a list of all grasshopper-types
#circle = ghCircle.Value # access the "real" circle
rhinoDoc = RhinoDoc.ActiveDoc
ghCircle.BakeGeometry(rhinoDoc, rhinoDoc.CreateDefaultAttributes(), System.Guid())
The file I had on the desktop is attached.
Also, you get autocompletion with types after using clr.AddReferenceByName the first time, which is pretty useful.
EDIT, 2020/Feb/19: Script edited to account for SDK changes.
McNeel Europe, Barcelona
It has been a while, but back with questions again..
I've been trying to understand your script and adapt it in such a way that i can use it.
At the moment i seem to be able to change a few parameters, but other than lines, curves and circles have been difficult. No idea how to change a slider or move component yet. (is there any way to find their names or what code to use?)
All i try now is to change the length of a line and draw a circle at the end. Once the circle is drawn, i want to measure the radius and if this radius is not the previous radius length it should continue with the loop and add a line.
I'll add my grasshopper file and code.
Do you know how i can make this last step??
Thanks for your help!