Site Tools


Info: User Data Options in Rhino

Developer: C++
Summary: Discusses object user data options

Overview

There are three places you can attach user data to Rhino objects.

Attribute User Data - Attach the user data to the reference returned by CRhinoObject::Attributes(). This user data will persist through 3dm file IO. This user data persists when object attributes get copied (most commands). This is a good place to attach user data that does not depend on the specific geometry applications like rendering and animation.

// Attach attribute user data in a way that works with undo
CRhinoObject* obj = ...;
ONN_3dmObjectAttributes att = obj->Attributes();
CMyUserData* pMyUserData = new CMyUserData();
att.AttachUserData(pMyUserData);
obj->ModifyAttributes(att,true,true);

Geometry User Data - Attach the user data to the pointer returned by CRhinoObject::Geometry(). This user data will persist through 3dm file IO. This user data persists when commands make minor modifications to geometry (some commands). Attribute user data is generally a better choice. If you do not have a good reason for using geometry user data instead of attribute user data, then use attribute user data.

// Attach geometry user data in a way that works with undo
CRhinoObject* obj = ...;
CRhinoObject* newobj = obj->DuplicateRhinoObject();
ON_Geometry* newgeometry = const_cast<ON_Geometry*>(newobj->Geometry());
CMyUserData* pMyUserData = new CMyUserData();
newgeometry->AttachUserData(pMyUserData);
RhinoApp().ActiveDoc()->ReplaceObject(CRhinoObjRef(obj),newobj);

Runtime User Data - Attach the user data to the CRhinoObject pointer. This user data is NEVER SAVED in 3dm files. Often, this user data will not persist through commands that modify geometry. Generally, you want to use attribute or geometry user data.

// Attach runtime object user data in a way that works with undo
CRhinoObject* obj = ...;
CRhinoObject* newobj = obj->DuplicateRhinoObject();
newobj->AttachUserData(pMyUserData);
RhinoApp().ActiveDoc()->ReplaceObject(CRhinoObjRef(obj),newobj);


developer/sdksamples/userdatainfo.txt ยท Last modified: 2015/09/14 (external edit)