Force to ReRead the 3Dm document


#1

Hello,
probably because in two hours it is holiday, I don’t find a method to re read a document.
In fact I have a 3dm file contained serialized object. And I would like to be able to read the document 3dm every where in my code.
To be mo precise :
the overriden Read function become

protected override void ReadDocument(RhinoDoc doc, BinaryArchiveReader archive, FileReadOptions options)
{
   list.Clear();
    //read the user data and push it into the singleton instance
    if (list.Read(archive))    {} //where archive is BinaryArchiveReader type
}

The Read() function works if the plugin has been loaded and then the user ask to open some 3dm file.

Now if we take an another order :
1.Read the 3dm document
2.Load the plugin
I need to call the ReadDocument functions to deserialize the objects contained in the 3dm.file. so I need to get the archive.
How to get the BinaryArchiveReader archive ?


(Dale Fugier) #2

Hi Markus,

When Rhino opens a 3dm file that contains plug-in document data, if the owning plug-in is not loaded then Rhino will automatically load the plug-in and call it’s PlugIn.ReadDocument override.

You can verify this by testing the SampleCsUserData RhinoCommon sample.

With this said, I am not sure I understand what you are wanting to do and why. Perhaps I need more information?

– Dale


#3

Hello Dale,
It is not exactly like I thought. Im fact my question is how to force to
read again the document. Because when the document 3dm is opened before you
have started the plugin, the plugin doesn’t try to read the currently
opened Document. This is a problem because my document have some document
data that I have previously stored in.


(Dale Fugier) #4

The only way to re-read the document is to re-run the Open command.

Also, what you are saying is not how Rhino works. As I have said, When Rhino opens a 3dm file that contains plug-in document data, if the owning plug-in is not loaded then Rhino will automatically load the plug-in and call it’s PlugIn.ReadDocument override. Granted, the owning plug-in must be already installed on the system.

– Dale


#5

Hello Dale,
Where is the definition for the Open command ?
I thaught to implement it into the OnLoad() function :

   protected override Rhino.PlugIns.LoadReturnCode OnLoad(ref string errorMessage)
    {

       
        //affect the delegates when some new documents are called happens
        Rhino.RhinoDoc.NewDocument += new EventHandler<DocumentEventArgs>(RhinoDoc_NewDocument);
        Rhino.RhinoDoc.BeginOpenDocument += new EventHandler<DocumentOpenEventArgs>(RhinoDoc_BeginOpenDocument);
        Rhino.RhinoDoc.EndOpenDocument += new EventHandler<Rhino.DocumentOpenEventArgs>(RhinoDoc_EndOpenDocument);
      
        
        System.Type complete_panel = typeof(CompleteHost);
        
        Panels.RegisterPanel(this, complete_panel, "Strategie_panel", Properties.Resource1.Main);
        if (Rhino.RhinoDoc.ActiveDoc.Name != "") {             
           //here I should read the document user data

        }             
      

        return LoadReturnCode.Success;
    } 

as you can see the comment, I need to read the document user data. The only think is how?
the best thing would be to get the BinaryArchiveReader from rhino. Do you have some Idea or a simple example to provide? Perhaps the secret in your SampleCsUserdata is the implemantation from “SampleCsUserdata Instance”