OnDocumentChange event not firing

OnDocumentChange event not firing

ajcampbell
Contributor Contributor
2,502 Views
7 Replies
Message 1 of 8

OnDocumentChange event not firing

ajcampbell
Contributor
Contributor

I can't figure out what I've got wrong here, I'm trying to create a handler for the OnDocumentChange Application event. 

 

private Inventor.Application m_inventorApplication;
Inventor.ApplicationEvents appEvents = null;

public StandardAddInServer()
{
}

public void Activate(Inventor.ApplicationAddInSite addInSiteObject, bool firstTime)
{
// Initialize AddIn members.
m_inventorApplication = addInSiteObject.Application;
appEvents = m_inventorApplication.ApplicationEvents;
appEvents.OnDocumentChange += appEvents_OnDocumentChange;
appEvents.OnSaveDocument += appEvents_OnSaveDocument;
}

void appEvents_OnSaveDocument(_Document DocumentObject, EventTimingEnum BeforeOrAfter, NameValueMap Context, out HandlingCodeEnum HandlingCode)
{
MessageBox.Show("On Save");
HandlingCode = Inventor.HandlingCodeEnum.kEventNotHandled;
}

void appEvents_OnDocumentChange(Inventor._Document DocumentObject, Inventor.EventTimingEnum BeforeOrAfter, Inventor.CommandTypesEnum ReasonsForChange, Inventor.NameValueMap Context, out Inventor.HandlingCodeEnum HandlingCode)
{
MessageBox.Show("On Document Change");
HandlingCode = Inventor.HandlingCodeEnum.kEventNotHandled;
}

 

My OnSaveDocument handler works just fine but the OnDocumentChange will not fire. I've been using the even watcher and have been using other handlers but cannot seem to get this one to work. Any ideas would be 

appreciated.

Thanks

0 Likes
Accepted solutions (1)
2,503 Views
7 Replies
Replies (7)
Message 2 of 8

philippe.leefsma
Alumni
Alumni

Hi,

 

So far I do not reproduce the behavior on my side. Those events are fired properly. Which version of Inventor are you running? What's the behavior with the EventWatcher, is OnDocumentChange visible with that tool?

 

I'm attachine the addin I used to test, just in case you missed something in your project.

 

Regards,

Philippe.



Philippe Leefsma
Developer Technical Services
Autodesk Developer Network

0 Likes
Message 3 of 8

maxstels
Contributor
Contributor
i also have this problem on Inventor 2014 sp1
0 Likes
Message 4 of 8

ajcampbell
Contributor
Contributor

Thanks Philippe,

So here's the situation. We use Inventor 2013 and I have been writing all my addi-ins using Visual Studio 2012 express since that was the version I was already familiar with. I installed the Inventor SDK wizard using the method listed here http://forums.autodesk.com/t5/Autodesk-Inventor-Customization/Autodesk-Inventor-Wizards-for-Microsof.... When I didn't have some of the new methods available I posted here and found that I was referencing the inventor interop version 16.0.0.0 instead of 17.0.0.0. I deleted that reference added a new one to version 17 from the program files folder and everything seemed to be working fine. Every time I started a new addin I would need to change my reference but other than that there seemed to be no difference, until this issue.

 

When I got the file from you I initially opened it in VS2012, built it and ran it and it worked, just as expected. So I started a new project with the wizard, pasted your code, changed my reference, and it would not work. Only the onsave event was firing. So I installed a version of VS2010, installed the add-in wizard, new project works great. I checked the path of the reference that was working and saw it was not in the program files folder, but in a windows assembly folder, so I tried again in 2012 with the new reference with no luck. I am always targeting .net version 4.0 so I think all of my code will work fine in VS2010 but I would prefer to use 2012 since I am using it for some other development. Is there some other reason why add-ins written in 2010 would be different than ones written in 2012? Or is there some other template that I can use to write in 2012? Thanks again for all your help, if nothing else think I can just use 2010 and it will get me there.

Cheers-

Andy

0 Likes
Message 5 of 8

ajcampbell
Contributor
Contributor

I just moved the template file from my VS2010 templates to my VS2012 templates and it worked. I attached it in case anyone else is having trouble with this. You still need to change path for the maifest post build event to from  "%VS100COMNTOOLS%vsvars32" to  "%VS110COMNTOOLS%vsvars32" before you build.

0 Likes
Message 6 of 8

maxstels
Contributor
Contributor

i send this issue   Case 08824333 to Support ADN, my project in to vb.net use Visual Studio 2012

0 Likes
Message 7 of 8

philippe.leefsma
Alumni
Alumni
Accepted solution

Try always setting the "Embed Interop Types = False" for the Inventor reference. This fixes the issue in my case:

 

img.png



Philippe Leefsma
Developer Technical Services
Autodesk Developer Network

Message 8 of 8

ajcampbell
Contributor
Contributor

This does it, Thanks!

Changing to the non-embedded interop does require some extra casting (no dynamic variables), but my event handlers will all trigger now. In googling why this worked I did run across this from Mod the Machine http://modthemachine.typepad.com/my_weblog/2012/07/set-embed-interop-types-to-false-to-avoid-problem... for future reference.

Thanks again for your help Philippe