Modify Object Attributes (Rather Than Baking with Attributes)

Hi everyone ( and I guess more specifically @DavidRutten) !

I know there are gh components that can bake objects with attributes. What I want to achieve is to directly modify the object attributes from gh.python. Something like:

scriptcontext.doc.Objects.ModifyAttributes(objref, attr, False)

It seems that grasshopper only reference to geometry. So I tried to use rs.getObjects directly in GH.python, and it is of no avail.

Is there any workaround I can take? Thanks in advance!

Human has a component called Modify Object Attributes that will let you modify the attributes of an existing object. Does that help?

Thank you @andheum . That is indeed an option. I would like also know how the script can work out, since I may integrate other operations with modifying object attributes through GHpython.

The important thing to note is that Rhino has RhinoObjects, which are both a Geometry and an ObjectAttributes rolled up into one, and Grasshopper typically strips this information out of an object to yield only the Geometry (which can be Brep, Curve, etc).

If you have an object generated in Grasshopper, it cannot have attributes. If you want to Bake with attributes, you have to add the object with one of the RhinoDoc.Objects.AddXXX(object, attributes) method such as AddCurve().

If you want to modify the attributes of an existing referenced object – that is, one that already exists in Rhino – I find it easiest to convert the referenced object to its GUID by passing it through a GUID param, and then use RhinoDoc.Objects.Find(id) to retrieve the RhinoObject. From there you can modify its Attributes property; just remember to call CommitChanges() on the object to make sure the modifications β€œtake.”

Hi @andheum,

After my fiddling around, I finally figured out that I did not use the scriptcontext.doc correctly. The below documentation is very helpful for anyone that has the same confusion.

Custom GhPython Baking Component

So I just do scriptcontext.doc = Rhino.RhinoDoc.ActiveDoc, and problems solved.

Thank you for taking the time to explain this to me.


1 Like