Access to exported document, exporting 3dm

Hello,

Anybody knows if there a way to access to the exported document when exporting?

I would like to write into the string table on the exported file, but I’m not sure about how to proceed, the document passed by args in the methods RhinoDoc.BeginSaveDocument and RhinoDoc.EndSaveDocument is the Active Doc, not the exported one, and the file path passed in the agrs (the target file or a temp file called rh$****.tmp when copying geo) is not accesible via File3dm due to the file is locked (by Rhino I guess)

Thank you.
Will

Specifically, what string table?

Rhino does not create a new document when saving or exporting. It just takes the existing document and serializes it to disk.

Can you please describe what you are trying to do and why?

Thanks,

– Dale

Hi @dale

Thanks for your answer, saving (_Save) just takes the existing document, but exporting doesn’t.
When RhinoDoc.BeginSaveDocument is fired by _Export or _Copy commands any string written into e.Document.Strings (the Active Doc) is not stored on the target 3dm file, I made a short video and a test project to show it:

Here the code for the plugin (no command needed)

using Rhino;
using Rhino.FileIO;
using System.IO;

namespace ExportPluginTest
{
public class ExportPluginTestPlugIn : Rhino.PlugIns.PlugIn
{
public static ExportPluginTestPlugIn Instance { get; private set; }

    public ExportPluginTestPlugIn()
    {
        Instance = this;
        RhinoDoc.BeginSaveDocument += RhinoDoc_BeginSaveDocument;
        RhinoDoc.EndOpenDocument += RhinoDoc_EndOpenDocument;
    }

    private void RhinoDoc_EndOpenDocument(object sender, DocumentOpenEventArgs e)
    {
        //Import & Paste
        if (e.Merge)
        {
            //Display strings from imported document
            var f3dm = File3dm.Read(e.FileName);
            RhinoApp.WriteLine($"Readed from Imported file \"{Path.GetFileName(e.FileName)}\" string count: {f3dm.Strings.Count}");
            for (int i = 0; i < f3dm.Strings.Count; i++)
            {
                RhinoApp.WriteLine($"-Key:{f3dm.Strings.GetKey(i)} value:{ f3dm.Strings.GetValue(i)}");
            }
        }

        //Display strings from active document
        RhinoApp.WriteLine($"Readed from Active Doc string count: {e.Document.Strings.Count}");
        for (int i = 0; i < e.Document.Strings.Count; i++)
        {
            RhinoApp.WriteLine($"-Key:{e.Document.Strings.GetKey(i)} value:{ e.Document.Strings.GetValue(i)}");
        }

    }

    private void RhinoDoc_BeginSaveDocument(object sender, DocumentSaveEventArgs e)
    {
        //Write to Active Doc
        e.Document.Strings.SetString("Key1", "value1");
        e.Document.Strings.SetString("Key2", "value2");

        //Display strings Active Doc
        RhinoApp.WriteLine($"Writen to Active Doc, string count: {e.Document.Strings.Count}");
        for (int i = 0; i < e.Document.Strings.Count; i++)
        {
            RhinoApp.WriteLine($"-Key:{e.Document.Strings.GetKey(i)} value:{ e.Document.Strings.GetValue(i)}");
        }

   
    }

}

}

Hey @Harper,

Rather than watching for RhinoDoc.BeginSaveDocument, try watching for the Save, SaveAs, and Export commands to begin using Command.BeginCommand.

– Dale

Hi @dale,

That works fine, thanks for your help!

Regards.
Will