I was following the method used in here to add curves into the rhino model.
But I’ve just encountered difficulty in creating point objects to the model if I pass through grasshopper definition.
What would be the correct method?
Here is the brief of the code.
#import modules
import compute_rhino3d.Util
import compute_rhino3d.Grasshopper as gh
import rhino3dm
import json
#run compute locally
compute_rhino3d.Util.url = "http://localhost:8081/"
post_url = compute_rhino3d.Util.url + "grasshopper"
#name of files
model = rhino3dm.File3dm()
input_filename = 'simple.ghx'
output_filename = 'simple.3dm'
#modify input values
pt_tr = gh.DataTree("RH_IN:Pt")
n = 2
for i in range(n):
ptk = rhino3dm.Point3d(i,i,i)
ptk = json.dumps(ptk.Encode())
pt_tr.Append([i],[ptk])
trees = [pt_tr]
output = gh.EvaluateDefinition(input_filename, trees)
def ns(name):
for i in range(len(values)):
vname = values[i]["ParamName"]
if (vname == "RH_OUT:" + name):
return i
tag = "Pt"
dsind = ns(tag)
branch = output['values'][dsind]['InnerTree']['{0}']
item = branch[0]["data"]
json_item = json.loads(item)
#this part would not work???
p = [rhino3dm.CommonObject.Decode(json_item)]
#ideally I should be able to create objects
model.Objects.Add(p[0])
model.Write(output_filename)
here are the files that I used
simple.ghx (119.4 KB)
simple.py (2.9 KB)