algorithmic modeling for Rhino
Tags:
Hi Kirk,
how is this development going? If you still need some help, could you please start a new discussion? (this one is a bit old)
Thanks,
- Giulio
__________________
giulio@mcneel.com
McNeel Europe
Hi Tijl,
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")
import System
import Rhino
import Grasshopper
from Rhino import RhinoApp, RhinoDoc
from Rhino.Geometry import *
gh = RhinoApp.GetPlugInObject("Grasshopper")
gh.LoadEditor()
gh.CloseAllDocuments()
gh.ShowEditor()
gh.OpenDocument("C:\\Users\\MY_ACCOUNT_NAME\\Desktop\\test.ghx")
docServer = Grasshopper.GH_InstanceServer.DocumentServer
doc = docServer[0] # first opened document
def FindBatteryByNickname(docObjects, name):
if docObjects is None: return None
for obj in docObjects:
attr = obj.Attributes
if attr.PathName == name:
return obj
raise Exception(name + " was not found in document")
param = FindBatteryByNickname(doc.Objects, "myBegin")
if param is not None:
param.Script_ClearPersistentData()
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[0][0] # 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.
- Giulio
________________
giulio@mcneel.com
McNeel Europe, Barcelona
Giulio,
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!
Tijl
Welcome to
Grasshopper
Added by Parametric House 0 Comments 0 Likes
Added by Parametric House 0 Comments 0 Likes
Added by Parametric House 0 Comments 0 Likes
Added by Parametric House 0 Comments 0 Likes
Added by Parametric House 0 Comments 0 Likes
© 2024 Created by Scott Davidson. Powered by