How to save custom grips object to 3dm file?


#1

Hi,

I don’t find a way to do this in C++.
For example, with @dale’s SampleCustomGrips, I create a rectangle, edit the grips, then save the file. When I open it again and edit them, they are no longer the custom grips, but the default polyline ones.

How to keep the custom grips within the file?

Many thanks,
Pablo


(Dale Fugier) #2

Hi Pablo,

Keep in mind that grips are not saved in a 3dm file. Rather, there are created, somewhat on the fly, when the user wants to use them.

Does does get saved in 3dm files are objects that inherit from CRhinoObject.

By design, Rhino will not save custom CRhinoObject-derived classes. This means, the CRhinoRectangleObject found in the sample you referenced, will not be saved in he file. Rather, it’s base class, or CRhinoCurveObject, will be saved.

Thus, the technique you can use to round trip custom objects, such as CRhinoRectangleObject is to attached a piece of custom user data to the object that saves with the base object. Then when Rhino reads the 3dm file, check to see if the object has your custom data and, if so, convert it back to your derived class type.

The SampleMarker SDK sample project demonstrates how to do this.

https://github.com/mcneel/Rhino5Samples_CPP/tree/master/SampleMarker

Does this help

– Dale


#3

Hi Dale,

Thanks for the hint and the sample! I’ll take a look :wink:

Pablo


#4

Hi Dale,

It works indeed.

Just as a side question: is it possible to change the object mode of a CRhinoGripObject from normal to hidden and vice versa?
I tried the method ModifyAttributes but it doesn’t seem to do it (actually it is an override to “prevent” changing grip attributes). I also tried HideGrip but it doesn’t work neither.

Many thanks,
Pablo


(Dale Fugier) #5

Sorry, no. You can only hide top-level objects. You can turn grips on (show) and turn them off (hide).

– Dale


#6

Good to know! Thanks for the info.

Pablo