Document path non updated

I tried this program, but I cannot read the path of 3dm file.
protected override void ReadDocument(RhinoDoc doc, BinaryArchiveReader archive, FileReadOptions options)
// Read plug-in document data.

    // If our document data is found in a 3DM file, we are
    // required to read it. But, we don't necessarily want
    // to use it.

    // If the user is creating a new model, or opening an existing
    // model, we'll want to keep the document data that we read.
    // Otherwise, we'll read the data, but not use it. This way,
    // we won't overwrite out data if the user is importing geometry,
    // from another 3DM file.
    //        bool bKeepData = (options.NewMode || options.OpenMode) ? true : false;

    //        if (bKeepData)
    //           _stringTable.Clear();

    // Read the major and minor version of the document data
    int major = 0, minor = 0;
    archive.Read3dmChunkVersion(out major, out minor);
    string pathname="rh$";

    // At this point, if we've changed the format of
    // our document data, we'll want to compare the
    // major and minor revision numbers and read our
    // data accordingly.
        pathname = archive.ReadString();
        string nomefile = System.IO.Path.GetFileName(pathname);
        string document = Rhino.RhinoDoc.ActiveDoc.Path;

// Here document =’’ <-----
var type = typeof(MainPanel);
MainPanel ppp = (MainPanel)Rhino.UI.Panels.GetPanel(type.GUID);
if ((pathname != null) && (System.IO.File.Exists(pathname)))

    catch (System.Exception ex)
        if (pathname.Contains("rh$") == false)
            Rhino.RhinoApp.WriteLine("File jobs: {0} read failed!", ex.Message);

First, try formatting your code between three backticks:

your code here

What I think is happening here is that RhinoDoc.ActiveDoc is only set after the file has been read completely. Here you try to retrieve it while it is being opened.

Thank you. Any idea or suggestion to workaround this?

Subscribe to the EndOpenDocument event, then read the new document location.

but have not any example?


Subscribe to the event

RhinoDoc.EndOpenDocument += OnEndOpenDocument;

And implement the event handler

void OnEndOpenDocument(object sender, DocumentOpenEventArgs args)
    string newDocumentPath = args.FileName;

To unsubscribe from the event

RhinoDoc.EndOpenDocument -= OnEndOpenDocument;

Thank you
I inserted your code. It works but the property ActiveDoc.Path is already null.

private void OnEndOpenDocument(object sender, DocumentOpenEventArgs e)
var a=0;
–> string document = Rhino.RhinoDoc.ActiveDoc.Path;


See my code again. You did not use args.FileName

Thanks a lot. Works. Was my mistake…