/// <summary> /// 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. /// </summary> protected override void ReadDocument(RhinoDoc doc, BinaryArchiveReader archive, FileReadOptions options) { archive.Read3dmChunkVersion(out var major, out var minor); if (MAJOR == major && MINOR == minor) { // Always read user data even though you might not use it. var string_table = new SampleCsStringDocumentData(); string_table.ReadDocument(archive); var simple_table = new SampleCsSimpleDocumentDataTable(); simple_table.ReadDocument(archive); var dictionary = archive.ReadDictionary(); if (!options.ImportMode && !options.ImportReferenceMode) { if (string_table.Count > 0) { StringDocumentDataTable.AddRange(string_table.ToArray()); } if (simple_table.Count > 0) { SimpleDocumentDataTable.AddRange(simple_table.ToArray()); } if (null != dictionary && dictionary.Count > 0) { Dictionary = dictionary; } } } }
/// <summary> /// OnCloseDocument event handler. /// </summary> private void OnCloseDocument(object sender, DocumentEventArgs e) { // When the document is closed, clear our // document user data containers. StringDocumentDataTable.Clear(); SimpleDocumentDataTable.Clear(); Dictionary.Clear(); }
/// <summary> /// Called when Rhino is saving a .3dm file to allow the plug-in to save document user data. /// </summary> protected override void WriteDocument(RhinoDoc doc, BinaryArchiveWriter archive, FileWriteOptions options) { // Write the version of our document data archive.Write3dmChunkVersion(MAJOR, MINOR); // Write the string table StringDocumentDataTable.WriteDocument(archive); // Write the simple table SimpleDocumentDataTable.WriteDocument(archive); // Write the dictionary archive.WriteDictionary(Dictionary); }