'If you want to write plug-in document data when a model is saved, you must override 'this function and return true 'This function is called by rhino right before a file is saved. It is asking the plug-in 'if it has any data that should be saved in the .3dm file. If this function returns true, 'then Rhino knows to set up a segment in the saved 3dm file for this plug-in and Rhino 'will eventually call WriteDocument
Public Overrides Function CallWriteDocument(ByVal options As IRhinoFileWriteOptions) _ As Boolean 'only return true if you REALLY want to save something to the document 'that is about to be written to disk If (options.Mode(IRhinoFileWriteOptions.ModeFlag.SelectedMode) = True) Then Return False If (options.Mode(IRhinoFileWriteOptions.ModeFlag.AsVersion2) = True) Then Return False If (options.Mode(IRhinoFileWriteOptions.ModeFlag.AsVersion3) = True) Then Return False 'perform some other type of check to see if you need to save any data... 'If( IHaveDataToWrite() = False ) Then Return False Return True End Function 'If any ON_BinaryArchive::Write*() functions return false than you should 'immediately return false otherwise return true if all data was written 'successfully. Returning false will cause Rhino to stop writing this document. Public Overrides Function WriteDocument(ByVal doc As MRhinoDoc, _ ByVal archive As OnBinaryArchive, _ ByVal options As IRhinoFileWriteOptions) _ As Boolean 'This function is called because CallWriteDocument returned True. 'Write your plug-in data to the document Dim date_string As String = System.DateTime.Now.ToShortDateString() Dim time_string As String = System.DateTime.Now.ToShortTimeString() 'It is a good idea to always start with a version number 'so you can modify your document read/write code in the future If (archive.Write3dmChunkVersion(1, 0) = False) Then Return False If (archive.WriteString(date_string) = False) Then Return False If (archive.WriteString(time_string) = False) Then Return False Return True End Function 'Called whenever a Rhino document is being loaded and plug-in user data was 'encountered written by a plug-in with this plug-in's GUID. ' 'If any ON_BinaryArchive::Read*() functions return false than you should 'immediately return false otherwise return true when all data was read. Public Overrides Function ReadDocument(ByVal doc As MRhinoDoc, _ ByVal archive As OnBinaryArchive, _ ByVal options As IRhinoFileReadOptions) _ As Boolean 'Always read data in the EXACT same order you wrote it Dim major As Integer, minor As Integer If (archive.Read3dmChunkVersion(major, minor) <> True) Then Return False 'If you've changed you reading/writing code over time, 'you can use the version number of what you read 'to figure out what can be read from the archive If (major > 1 Or minor > 0) Then Return False 'the data you read/write will probably be member variables of your plug-in class, 'but for simplicity this sample is just using locally defined strings Dim date_string As String = Dim time_string As String = If (archive.ReadString(date_string) = False) Then Return False If (archive.ReadString(time_string) = False) Then Return False Return True End Function