Site Tools


Rhino 4.0: Saving Plug-in User Data in V3 Files

C++

Version: Rhino 4

The SaveAs feature in Rhino 4.0 can be used to write files that Rhino 3.0 can use. By default, plug-in user data is not saved when you save a V3 file from Rhino 4.0. If you feel need this, and you are willing to do some extra coding and lots of detailed testing, it is possible to round-trip plug-in user data between Rhino 3.0 and Rhino 4.0.

There are several approaches available. The one you choose depends on what you want to accomplish.

There is not a V3 version of the plug-in. You want your V4 plug-in to be able to round-trip information through V3 files.

  • In your V4 plug-in, override CRhinoPlugIn::SaveAsV3() and return true. This insures your V4 plug-in will save its information in V3 files. Since the plug-in ID and any object user data IDs will not be recognized by V3, V3 will simply let the “alien” information persist unchanged.

There is a V3 version of the plug-in. You want your V4 plug-in to be able to round-trip information through V3 files. You do not want the V3 and V4 plug-ins to exchange information.

  • In your V4 plug-in, override CRhinoPlugIn::SaveAsV3() and return true. This insures your V4 plug-in will save its information in V3 files.
  • Make certain your V4 plug-in id is not equal to your V3 plug-in ID. This insures the plug-ins will not attempt to read/write each other's document user data.
  • Make certain there are no shared ids in the ON_OBJECT_IMPLEMENT() macros or in the m_userdata_id fields in your V3 or V4 plug-ins. This insures the plug-ins will not attempt to read/write each other's object user data.

There are V3 and V4 versions of your plug-in. You want the V3 and V4 plug-ins to share information.

This level of support requires expert programming, through testing, and thoughtful file IO code design. In particular, if you have changed the information your plug-in saves and you did not carefully plan for this situation when you wrote your V3 plug-in's IO code, then it is likely you cannot provide this level of file support for your users. To properly test your code, you must be able to run your V3 and V4 plug-ins in a debugger.

  • In your V4 plug-in, override CRhinoPlugIn::SaveAsV3() and return true. This insures your V4 plug-in will save its information in V3 files.
  • Make certain your V4 plug-in ID is identical to the V3 plug-in ID. This insures the plug-ins will read/write the same document user data.
    • Make certain your V4 plug-in will read the document user data saved by your V3 plug-in. To do this, run Rhino 3.0 with your V3 plug-in and save a V3 file. Start Rhino 4.0 and put a debugger breakpoint on the first line of the V4 plug-in's ReadDocument() function. Open the file you saved from Rhino 3.0. Step through your V4 plug-in's ReadDocument() code line-by-line and make 100% sure it is reading exactly what the V3 plug-in wrote. Repeat this test with at least a dozen files containing different models and different amounts of V3 document user data.
    • Make certain your V3 plug-in will read the document user data saved by your V4 plug-in. To do this, run Rhino 4.0 with your V4 plug-in and use Rhino 4.0's SaveAs command to write a V3 file. Start Rhino 3.0 and put a debugger breakpoint on the first line of the V3 plug-in's ReadDocument() function. Open the V3 file you saved from Rhino 4.0. Step through your V3 plug-in's ReadDocument() code line-by-line and make 100% sure it is reading exactly what the V4 plug-in wrote. Repeat this test with at least a dozen files containing different models and different amounts of V4 document user data.
  • Make certain the class ids used in ON_OBJECT_IMPLEMENT and the values used in ON_UserData::m_userdata_id exactly the same in your V3 and V4 plug-ins. This insures the plug-ins will read/write each other's object user data.
    • Repeat the two tests described above except put the breakpoints in the Read(ON_BinaryArchive&) functions of every single object user data class in your plug-ins.
developer/multiversionuserdatasupport.txt · Last modified: 2016/04/04 by sandy