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:
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.β
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.