Hi,
I would like to ask about rhino objects and RhinoCommon.
Consider following situation (Outside Grasshopper, only Rhino):
a) I have a python library that has a custom class.
b) I would like to “attach” that class to a Rhino geometry object e.g. mesh or brep box.
c) after doing some usual manipulation to a rhino geometry e.g. transformation, I would like to read the element again and go through that class properties.
How you would do it? What is the most typical workflow.
I am wondering if there are example files how create a custom rhino objects, including preview/display pipelines, serialization within python context?
Presumably you mean class instances, not a class (or all objects will be attached to the same class). I’m pretty sure you can just do:
rhino_geom_object.attribute_name = class_instance
print(rhino_geom_object.attribute_name.class_attribute_name)
If everything you’re doing is in the same Python process, and there’s no need to make that rhino_geom_object available in another process, I don’t see any need to serialise the class instance.
To save the class instance along with all the info in the Rhino document, and to allow Python code to read it in the same way later, I’ve never tried it but I would serialise it with json.dumps
of vars
if possible, e.g. if it’s a simple data holding class. Use pickle
if not. And then write the serialised version on to the object’s User Text. Pickling might require an ascii string of the bytes.