doc.Path is empty when overriding ReadDocument method (Windows)

So I try to override the ReadDocument method which gets called when I open a .3dm-file, right?. So I have a file called “name.3dm” already saved on my machine and when I open it, the breakpoint I set in my override ReadDocument method works, but the doc.Path field is empty. Why is that?

Btw: The name is empty too, but all the other data is there, like the materials and objects and so on…

Hi @Ivan1,

Does this help?

Hi @dale,

Yes, this workaround does works if the following is true:
DocumentEventArgs e as parameter and then e.Document is the same as (equivalent to)
DocumentOpenEventArgs e and then e.Document in this only case of OnEndOpenDocument()

P.S. Is it weird that for Mac I don’t need this workaround and doc.Path is not empty?

Knowing the internal difference between the two versions, no. But thanks for point this out.

– Dale

@dale this wasn’t fixed ? I’m looking for other files in diectory where 3dm file is located during reading archive and also stuck on this. OnEndOpenDocument is before ReadDocument?

Besides any real reason why this is null during reading doc?

Hi @D-W,

If obtaining the document path is important, then use this pattern. Note, Rhino opens more than just .3dm files. Thus, RhinoDoc.Path can still be null even after Rhino has returned control to the user.

public class TestDocPath : Command
  private uint m_document_serial_number;

  public override string EnglishName => "TestDocPath";

  public TestDocPath()
    RhinoDoc.EndOpenDocument += OnEndOpenDocument;

  private void OnEndOpenDocument(object sender, DocumentOpenEventArgs e)
    RhinoApp.WriteLine("  FileName: {0}", string.IsNullOrEmpty(e.FileName) ? "<empty>" : e.FileName);
    RhinoApp.WriteLine("  DocPath: {0}", string.IsNullOrEmpty(e.Document.Path) ? "<empty>" : e.Document.Path);
    m_document_serial_number = e.DocumentSerialNumber;
    RhinoApp.Idle += OnIdle;

  private void OnIdle(object sender, EventArgs e)
    RhinoApp.Idle -= OnIdle;
    var doc = RhinoDoc.FromRuntimeSerialNumber(m_document_serial_number);
    if (null != doc)
      RhinoApp.WriteLine("  DocPath: {0}", string.IsNullOrEmpty(doc.Path) ? "<empty>" : doc.Path);

  protected override Result RunCommand(RhinoDoc doc, RunMode mode)
    // TODO
    return Result.Success;

– Dale