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

@dale I’m having trouble with idle it seems not performing code that is written and can debug it as VS tells me that somehow on fly source code has changed (?) it behaves really strange. Any ideas?

[EDIT]: No worries VS just got crazy for some reason after reboot back to normal.

Maybe i’m doing too much though i tried to do the same as above for document unit system but seems this is read wrong so i had to read it via File3dm.Read … I tried to use e from EndOpenDocument or ReadDocument but i always get invalid results there.

[EDIT]: Though above still remains true - It’s bit weird that for eg. on import all Open events are launched but there is no access to imported file and doc properties don’t you think?