Serializing non-Rhino classes to a Rhino File

Thanks. :slight_smile:

This write the class as an object Data User , If you would like to write in the document User data, do you need a list stuart data and then write it with the function : ???

protected override void WriteDocument(RhinoDoc doc, BinaryArchiveWriter archive, FileWriteOptions options)
        {
            // Write plug-in document data

            // Write the major and minor version of document as document data
            archive.Write3dmChunkVersion(1, 0);

            // Write the number of string we intend to write as document data
             archive.WriteInt(list_of_stuartData.Count);

            // Write our string table as document data
           for (int i = 0; i < list_of_stuartData.Count; i++)
               archive.WriteString(list_of_stuartData[i]);
        }

Hi Markus,

I’m not sure what the question is, or even if there is a question. Can you please clarify?

Thanks,

– Dale

Hello Dale, Sorry for my late answer.
If you use the Write function it is a sort of serializing (the Rhino Way), isn’t it?

If I a have a class with a list of classes
List<my_classes> and I want to chose to save some ef items contained into the list. How can I do it with the WriteDocument function?

I have:

[Serializable]
Class MyOwnClass{
       public MyOwnClass(){}
      public MyOwnClass(MyOwnClass src){ ....}
     public Write(binaryArchiveWriter archive){.. }
     public Read(BinaryArchiveWriter archive){...}
}

[Serializable]
Class ListOfMyOwnClass{
       List<MyOwnClass>    ListOfMyOwnClass = new List<MyOwnClass>();
      public MyOwnClass(){}
      public MyOwnClass(MyOwnClass src){ ....}
     public Write(binaryArchiveWriter archive){.. }
     public Read(BinaryArchiveWriter archive){...}
}

and now in WriteDocument(…){
I am looking for a Way to write in the 3Dm. file a Way to write all the element of the list ListOfMyOwnClass
}

how to do it?

hmmm… I have tried a Way to answer but I don’t think it is the right way to do it.

  1. if I want to save the ListOfMyOwnClass from the WriteDocument() I have Implement it like

    protected override void WriteDocument(RhinoDoc doc, BinaryArchiveWriter archive, FileWriteOptions options)
     {
    
         list_of_my_own_class.WriteList(archive);
     }
    

and in my Class ListOfMyOwnClass I have :
Public ListOfMyOwnClass {

    protected override bool Write(Rhino.FileIO.BinaryArchiveWriter archive)
    {

         var dict = new Rhino.Collections.ArchivableDictionary(1, "ListStrategie");
        for (int i = 0; i < list_of_my_own_class.Count; i++)
        {
            
            dict.Set("name1"+i.ToString(), list_of_my_class[i].objet1.name1);
            dict.Set("name2"+i.ToString(), list_of_my_class[i].objet1.name2);
            
        }

        archive.WriteDictionary(dict);           
        return true;
       }


  public void WriteList(Rhino.FileIO.BinaryArchiveWriter archive){
           Write(archive);
      }

 }

So I use something like a wrapper.

But there are a lots of problems with this method : first I need to add the Class ListOfMyOwnClass to the object User

   protected override Result RunCommand(RhinoDoc doc, RunMode mode)
    {

        Rhino.DocObjects.ObjRef objref;
        Rhino.Input.RhinoGet.GetOneObject("", false, Rhino.DocObjects.ObjectType.AnyObject, out objref);

      ..............

If there are no objects drawned Into Rhino objRef is Null

Hi Markus,

It isn’t clear to me what you are trying to do or what your problem is. But attached is a plug-in sample that you might want to study. Hopefully it will clear things up a bit…

– Dale

TestMarkus.zip (5.2 KB)

1 Like

Thank you a lot, it is perfect. I have tried something like this before. It seems to be the best way.
Last Question : How would you Manage to write a Class who contains complicate cases like "ObservableCollections " in C# or other types?
I am over to questions you .

In the solution I posted, you should be able to swap the System.Collections.Generic.List for a System.Collections.ObjectModel.ObservableCollection.

– Dale