Felix1
February 26, 2020, 10:47pm
1
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)
{
RhinoApp.WriteLine("NewDocument");
//var dialog = new ProjectData(e.Document);
//dialog.RestorePosition();
//dialog.ShowModal(RhinoEtoApp.MainWindow);
//dialog.SavePosition();
}
but the WriteLine is never printed. What do i miss.
dale
(Dale Fugier)
February 27, 2020, 4:30am
2
Hi @Felix1 ,
Please review and let me know if you have any questions.
Hi @Darryl_Menezes ,
We always advise developers to not do too much in event handlers, especially document modifications. It’s better to set a flag and then handle the event later in a Rhino.Idle handler.
Here is a pattern I use frequently:
/// <summary>
/// Event handlers
/// </summary>
private EventHandler<DocumentEventArgs> m_new_document;
private EventHandler<DocumentOpenEventArgs> m_end_open_document;
private EventHandler m_idle;
/// <summary>
/// Event type
/// </summary>
enum EventType…
– Dale
Felix1
February 27, 2020, 9:59pm
3
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.
EDIT:
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
dale
(Dale Fugier)
March 2, 2020, 9:09pm
4
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
Felix1
March 2, 2020, 9:52pm
5
Thank you i have found a working solution based in this.
mingo1214
(Mingbo Peng)
April 25, 2020, 4:47am
6
Hi @dale , is it safe to say if Document.DateLastEdited
== Document.DateCreated
, than this document is a new document (no template or with template)?
dale
(Dale Fugier)
April 27, 2020, 11:43pm
7
Hi @mingo1214 ,
That is a reaonable assumption. But don’t hold me to it…
– Dale
1 Like