Site Tools


Differences

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

Link to this comparison view

developer:sdksamples:shareduserdata [2015/09/14] (current)
Line 1: Line 1:
 +====== Sharing User Data Between Plug-ins ======
 +> **Developer:​** //​[[developer:​cplusplusplugins|C++]]//​
 +> **Summary:​** //Discusses how to share object user data between plug-ins using the Rhino C++ SDK.//
 +
 +=====Question=====
 +I would like my plug-in'​s user data to be access from another plug-in. How can I do this?
 +
 +=====Answer=====
 +This is a question that we have been asked numerous time. Thus, the following sample:
 +
 +[[http://​wiki.mcneel.com/​_media/​legacy/​en/​TestSharedUserData.zip|Download:​ TestSharedUserData]] ​
 +
 +In a nutshell, the best way to share user data between plug-ins is to have access to the plug-in data controlled by a shared DLL - a DLL that is used by all interested plug-ins. ​ The user data class definitions and declarations,​ along with any helper functions used to access this data, are then added to and exported from this DLL.
 +
 +The easiest way to make DLLs for Rhino plug-ins is to simply run the Rhino Plug-in Wizard from Visual Studio. When the wizard finishes, simply delete the plug-in object (CPP and H files) and the command file. Then change the output file extension from RHP to DLL. Now, you have a MFC DLL that links with the Rhino SDK.
 +
 +One import piece of information to keep in mind is that when you create a class derived from **ON_UserData** and you expect this data to be serialized in a 3DM file, then you must assign the owning plug-in'​s guid to the **ON_UserData::​m_application_uuid** data member. This is how Rhino knows what plug-in to load when it encounters plug-in user data when reading a 3DM file. Note, it is not important what plug-in'​s uuid is assigned to the user data because all of the plug-ins are going to dynamically load the DLL when they are loaded anyway. But, some plug-in must be "in charge"​.
 +
 +For example:
 +
 +=====C++=====
 +<code c++>
 +ON_UUID CPlugInUserData::​PlugInId()
 +{
 +  // Copied from PlugIn1PlugIn.cpp
 +
 +  // {F8B054CD-19A3-4D46-AB7E-DB3E8EF8CF5B}
 +  static const GUID PlugIn1PlugIn_UUID =
 +  { 0xF8B054CD, 0x19A3, 0x4D46, { 0xAB, 0x7E, 0xDB, 0x3E, 0x8E, 0xF8, 0xCF, 0x5B } };
 +  return PlugIn1PlugIn_UUID;​
 +}
 +
 +CPlugInUserData::​CPlugInUserData()
 +{
 +  m_userdata_uuid = CPlugInUserData::​Id();​
 +
 +  /*
 +  CRITICAL:
 +    m_application_uuid must be assigned the uuid of the plug-in
 +    that will be responsible for reading and writing our user data.
 +    In this example, we'll use PlugIn1 as our primary plug-in.
 +  */
 +  m_application_uuid = CPlugInUserData::​PlugInId();​
 +
 +  m_userdata_copycount = 1; // enable copying
 +
 +  // initialize your data members here
 +  m_point.Set( 0.0, 0.0, 0.0 );
 +  m_string = L;
 +}
 +
 +</​code>​
 +The plug-in sample mentioned above contains two plug-in projects and one DLL project. To load the sample, just download and extract into some folder, and then open **Test.sln** is Visual Studio.
 +
 +
 +{{tag>​Developer cplusplus}}
  
developer/sdksamples/shareduserdata.txt ยท Last modified: 2015/09/14 (external edit)