Cancel
Showing results for 
Search instead for 
Did you mean: 
Highlighted

BeforeDocumentSave not being triggered

Phenom
Phenom

I'm writing an add-in for my company using the community templates, that should calculate and update a custom property on saving a document.

 

It was working fine, but now my handler is not being triggered by the BeforeDocumentSave event.

Via debugging I can see that the code to attach my handler in OnConnection is being run with no exceptions, and in Spy I can see the event is being called, but my method Handle_BeforeDocumentSave is not being called.

 

Has anyone any ideas as to what I might be doing wrong? 
(ST10 MP7)

 

Edit: Also, my ribbon bar is being loaded and works fine, so the Add-in is working to some extent.

 

 

 public override void OnConnection(SolidEdgeFramework.Application application, SolidEdgeFramework.SeConnectMode ConnectMode, SolidEdgeFramework.AddIn AddInInstance)
        {   
var events = (ISEApplicationEvents_Event)application.ApplicationEvents;
            events.BeforeDocumentSave += Handle_BeforeDocumentSave;
            
        }

 private void Handle_BeforeDocumentSave(object theDocument)
        {
            OnSaveClass.UpdateAsmMass(theDocument);
}

 

2 REPLIES

Re: BeforeDocumentSave not being triggered

Solution Partner Phenom Solution Partner Phenom
Solution Partner Phenom

Hi @Alex_H,

you have to use a variable for the ApplicationEvents object the persists.

Your  events variable will be destroyed when the program exits the OnConnection method. 

regards

JB
SE 2019, VS2017

Re: BeforeDocumentSave not being triggered

Phenom
Phenom

@JB Thanks a lot, that makes sense now that I know!