Grasshopper

algorithmic modeling for Rhino

Simple question: Trying to bake GH object into Rhino, doesn't work

# importing relevant modules
import rhinoscriptsyntax as rs
import Rhino
import scriptcontext as sc

# switch to gh document
sc.doc = "FitCrv.py"

# obtain object id (Instance GUID?)
obj_id = "5978a9d6-bdbe-4074-a080-711245f43ff1"

# change to rhino object
doc_obj = rs.coercerhinoobject(obj_id)

# set object attr and geom
attributes = doc_obj.Attributes
geometry = doc_obj.Geometry

# change to Rhino doc
sc.doc = Rhino.RhinoDoc.ActiveDoc

# add geom to Rhino
rhino_obj = sc.doc.Objects.Add(geometry, attributes)

This does not work. What am I doing wrong at the moment?

Views: 1347

Replies are closed for this discussion.

Replies to This Discussion

Hey Luc,

The following works:

import rhinoscriptsyntax as rs
import scriptcontext as sc
import Rhino

sc.doc = ghdoc

#get object id from grasshopper
obj_id = x
#convert grasshopper object into rhino object
doc_obj = rs.coercerhinoobject(obj_id)

#make attributes and geometry from rhino object
attributes = doc_obj.Attributes
geometry = doc_obj.Geometry

#go rhino document
sc.doc = Rhino.RhinoDoc.ActiveDoc

#bake object with attributes
rhino_obj = sc.doc.Objects.Add(geometry, attributes)
rs.ObjectColor(rhino_obj, y)

#back to gh
sc.doc = ghdoc

correct me if im wrong but I think assigning sc.doc to a str is not what you want..from what I understand you either target the ActiveRhinoDoc or the ghdoc.

then I dont understand why you want to feed a GUID into obj_id manually. Are you using objects that GH does not recognize? Plus you dont need to make it a str since GUID is a type..

GH deals with pure geometry objects so you wouldnt be able to get the GUID. If you reference geometry from the Rhino doc then you are able to get the GUID via the GUID component but that means you already have the geometry in the rhinoDoc..

What are you trying to do?

is the attached ok?

Attachments:

...ok cool

RSS

About

Translate

Search

Photos

  • Add Photos
  • View All

Videos

  • Add Videos
  • View All

© 2024   Created by Scott Davidson.   Powered by

Badges  |  Report an Issue  |  Terms of Service