Hi,
I noticed some strange behavior when opening files having plug-in data.
I override in my plug-in the method ReadDocument and listen for RhinoDoc.BeginOpenDocument event.
public MyPlugIn()
{
Instance = this;
RhinoDoc.BeginOpenDocument += OnBeginOpenDocument;
}
private void OnBeginOpenDocument(object sender, DocumentOpenEventArgs openEventArgs)
{
RhinoApp.WriteLine("Begin open document: " + openEventArgs.FileName);
RhinoApp.WriteLine(openEventArgs.FileName+" is {0}a reference", openEventArgs.Reference ? String.Empty : "not ");
}
protected override bool ShouldCallWriteDocument(FileWriteOptions options)
{
return true;
}
protected override void WriteDocument(RhinoDoc doc, BinaryArchiveWriter archive, FileWriteOptions options)
{
archive.WriteString(doc.Name);
}
protected override void ReadDocument(RhinoDoc doc, BinaryArchiveReader archive, FileReadOptions options)
{
bool empty = String.IsNullOrWhiteSpace(doc.Name);
if (!empty)
RhinoApp.WriteLine("doc variable name "+doc.Name);
else
RhinoApp.WriteLine("doc variable name [empty]");
String name = archive.ReadString();
RhinoApp.WriteLine("name when written "+name);
}
Output when reading file A.3dm after Rhino was started:
Begin open document: D:\temp\A.3dm
D:\temp\A.3dm is not a reference
doc variable name [empty]
Name when written A.3dm
Output when reading file B.3dm, when A.3dm is loaded:
Begin open document: D:\temp\B.3dm
D:\temp\B.3dm is not a reference
doc variable name [empty]
Name when written B.3dm
Output when attaching B as a reference with A active:
Begin open document: D:\temp\B.3dm
D:\temp\B.3dm is a reference
doc variable name A.3dm
Name when written B.3dm
Here is what I find strange:
- when reading a file, the doc variable’s name is empty
- the “Name when written” only shows up if a file is saved twice - after the first save it is empty when loaded.
- when attaching a reference model, the doc variable has the name of the active model, not the reference model. The documentation of ReadDocument (see http://4.rhino3d.com/5/rhinocommon/html/M_Rhino_PlugIns_PlugIn_ReadDocument.htm) clearly states that the doc variable is the document being loaded
Is this a bug? Is the documentation correct or incorrect?