Inventor Crashes after OnNewOccurrence event calls save?

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hi Everyone,
I'm working on writing some event handlers in c# for when a part is placed in an assembly. I'm trying to automatically suppress certain parts in certain levels of details.
The code to do this is pretty straightforward and actually works up if I don't call DocumentObject.Save(). I need to call this because otherwise the changes I make to each level of detail will be lost.
Stepping through and observing changes to the Inventor window everything looks like its working correctly up until the event handler returns. At that point Inventor crashes and the Inventor Error Report dialog comes up. Its 100% reliable and will always crash. In the dmpuserinfo.xml I get an "Access Violation" exception.
It seems like I am trying to do something at the same time as Inventor and I need to somehow wait until Inventor is done. I'm just not sure what I'm waiting for or how to wait.
Or may I'm doing something else horribly wrong.
What do you guys think?
Thanks!
if (SM.DialogResult == DialogResult.OK) { LocalDocumentObject.Save2(true); //this will crash foreach (string item in SM.SupressInLODs) { LevelOfDetailRepresentation TargetLOD = LocalDocumentObject.ComponentDefinition.RepresentationsManager.LevelOfDetailRepresentations[item]; if (LocalDocumentObject.ComponentDefinition.RepresentationsManager.ActiveLevelOfDetailRepresentation.Name != item) { TargetLOD.Activate(); } LocalOccurrence.Suppress(false); LocalDocumentObject.Save2(true); // this will crash. } }
<Requests last="AMxExtendedPlaceCompRequest" state="completed"> <Request name="AMxExtendedPlaceCompRequest"/> </Requests> <Exceptions> <Exception code="0xC0000005" text="ACCESS_VIOLATION" address="0x00007FFF1155A02A" extraInfo="module:C:\Program Files\Autodesk\Inventor 2017\Bin\FWUI.dll "> <AccessViolation type="Read" address="0x0000000000000000" PGStatus="0x00000001" accessing_null_ptr="true"/> </Exception> </Exceptions>