Execute method if new document is created

I like to execute a method of my plugin if a new document is created. Not if a existing document is loaded, only if a new one is created.

I think i should use

    protected override LoadReturnCode OnLoad(ref string errorMessage)
            RhinoDoc.NewDocument += OnNewDocument;
            return LoadReturnCode.Success;

    public static void OnNewDocument(object sender, DocumentEventArgs e)
        //var dialog = new ProjectData(e.Document);

but the WriteLine is never printed. What do i miss.

Hi @Felix1,

Please review and let me know if you have any questions.

– Dale

Thank you for the example but i think my problem is that the newDocument event is never been raised. Maybe i missunderstand when this event get called.

In my understanding RhinoDoc.NewDocument get executed if the user is open a new template via Data/New or the _new command.


I found that i need to override the PlugIn.LoadTime Property to “AtStartup” to get NewDocument raised on RhinoStartup, but still no trigger on _new

This is incorrect. RhinoDoc.NewDocument is triggered when you start a new, empty document. For example, you run the _New command and pick No Template.

If you run _New and pick a template, then both RhinoDoc.BeginOpenDocument and RhinoDoc.EndOpenDocument events will be triggered.

– Dale

Thank you i have found a working solution based in this.

Hi @dale, is it safe to say if Document.DateLastEdited == Document.DateCreated, than this document is a new document (no template or with template)?

Hi @mingo1214,

That is a reaonable assumption. But don’t hold me to it…

– Dale

1 Like