Inventor Crashes after OnNewOccurrence event calls save?

Inventor Crashes after OnNewOccurrence event calls save?

Anonymous
Not applicable
383 Views
1 Reply
Message 1 of 2

Inventor Crashes after OnNewOccurrence event calls save?

Anonymous
Not applicable

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>
0 Likes
384 Views
1 Reply
Reply (1)
Message 2 of 2

ruthsteed
Autodesk
Autodesk

Instead of making these changes in your event handler, try saving the information you need (like the placed occurrence information) and listening for the next UserInputEvents.OnTerminateCommand event.  Try making the LOD changes and document saves in that event handler.  I suspect you're listening for an event that happens during the place component when Inventor isn't ready to do things like save document.



Ruth Steed
Inventor Development Team
Autodesk, Inc.

0 Likes