Site Tools


Differences

This shows you the differences between two versions of the page.

Link to this comparison view

developer:sdksamples:userdatainfo [2015/09/14] (current)
Line 1: Line 1:
 +====== Info: User Data Options in Rhino ======
 +> **Developer:​** //​[[developer:​cplusplusplugins|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.
 +
 +<code c++>
 +// 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);​
 +</​code>​
 +
 +**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.
 +
 +<code c++>
 +// 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);​
 +</​code>​
 +
 +**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.
 +
 +<code c++>
 +// 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);​
 +</​code>​
 +
 +\\
 +
 +
 +{{tag>​Developer cplusplus}}
  
developer/sdksamples/userdatainfo.txt ยท Last modified: 2015/09/14 (external edit)