After opening an .iam via Api Inventor crashes when closing a document

After opening an .iam via Api Inventor crashes when closing a document

Anonymous
Not applicable
796 Views
8 Replies
Message 1 of 9

After opening an .iam via Api Inventor crashes when closing a document

Anonymous
Not applicable

Hello together,


since last year i've an sporadic issue when i open an .iam via the Api.


Here more details

- I'm using Inventor Build 284 2018.3.10.

- No visible or unvisble documents are opened

- An Vb.net addin is used to load the document


1. Loading an .iam with ThisApplication.Documents.Open("FFN.iam")

2. Open a Part of the assembly

3. Do nothing, only close the part

4. Inventor close the part document and shows the .iam

5. The UI freezes and after a few seconds Inventor crashes


If this error occurs it is reproducible until i do a little workaround.

As workaround it's enough to open the .iam once manually. After that the error won't occur even i restart the PC.

In the code to open the .iam is no transaction involved and also no silent operation is set to true.

Unfortunally i have no dumpdata until the next time the error occurs.

Has anyone an idea what causes the error and how to fix it?


Best regards

 

 

 

0 Likes
797 Views
8 Replies
Replies (8)
Message 2 of 9

bradeneuropeArthur
Mentor
Mentor

try this:

 

Dim openFileOptions As Inventor.NameValueMap  = thisapplication.TransientObjects.CreateNameValueMap
openFileOptions.Add("SkipAllUnresolvedFiles", True)
ThisApplication.Documents.OpenWithOptions("FFN.iam",openFileOptions)

Regards,

Arthur Knoors

Autodesk Affiliations & Links:
blue LinkedIn LogoSquare Youtube Logo Isolated on White Background


Autodesk Software:Inventor Professional 2025 | Vault Professional 2024 | Autocad Mechanical 2024
Programming Skills:Vba | Vb.net (Add ins Vault / Inventor, Applications) | I-logic
Programming Examples:
Drawing List!|
Toggle Drawing Sheet!|
Workplane Resize!|
Drawing View Locker!|
Multi Sheet to Mono Sheet!|
Drawing Weld Symbols!|
Drawing View Label Align!|
Open From Balloon!|
Model State Lock!
Posts and Ideas:
My Ideas|
Dimension Component!|
Partlist Export!|
Derive I-properties!|
Vault Prompts Via API!|
Vault Handbook/Manual!|
Drawing Toggle Sheets!|
Vault Defer Update!

! For administrative reasons, please mark a "Solution as solved" when the issue is solved !


 


EESignature

0 Likes
Message 3 of 9

Anonymous
Not applicable

Hi @Anonymous . I think this is related to using "ThisApplication.ActiveDocument vs ThisDoc.Document.

 

The assembly where the rule is running should be "ThisDoc.Document" or  something like "ThisAssembly.Document".

After opening the part, define it as "ThisApplication.ActiveDocument".

 

                
'Opening the part.
ThisApplication
.Documents.Open(oFile, True)
'After opening the part. Dim oDoc As Document = ThisApplication.ActiveDocument
'Do something here...
oDoc.Close(False)
Next 
0 Likes
Message 4 of 9

Anonymous
Not applicable

Hi,

thanks for your answers.

 

@bradeneuropeArthur:

I can be sure that there are no unresolved Files, because i usally restore all correspondending files from a .zip file. But i will give it a try after the error next occure.

 

@Anonymous:

Even if the .iam has some Rules in it i think they won't run before the doc was finally opened. The opening procedure runs via an VB.net addin.

 

Here's the code that does the work:

 

    Private Sub Wagen_Laden(WorkPfad As String, KonfigMainPfad As String, KonfigBasePfad As String, KonfigKonfigPfad As String, KonfigVBAProjektSavePfad As String, KonfigVBAProjektName As String, CADModell As String, DialogTitle As String)
        Dim oApp As Inventor.Application = g_inventorApplication
        Dim oDoc As Inventor.Document = oApp.ActiveDocument

        'Wenn Zipper nicht installiert dann raus
        If Not IsSevenZipInstalled(DialogTitle) Then
            Exit Sub
            'Else
            '    MsgBox("7-Zip richtig installiert", , DialogTitle)
            '    'Exit Sub
        End If

        'Wenn Dokumente in Inventor geöffnete dann raus, ansonsten Speicher bereinigen
        If oApp.Documents.VisibleDocuments.Count = 1 AndAlso oDoc.FullFileName <> CADModell Then
            MsgBox("Bitte schließen Sie vor Laden des Konfigurators alle geöffneten Dateien", vbInformation, DialogTitle)
            Exit Sub
        ElseIf oApp.Documents.VisibleDocuments.Count > 1 Then
            MsgBox("Bitte schließen Sie vor Laden des Konfigurators alle geöffneten Dateien", vbInformation, DialogTitle)
            Exit Sub
        ElseIf oApp.Documents.VisibleDocuments.Count = 1 AndAlso oDoc.FullFileName = CADModell Then
            MsgBox("Der Konfigurator ist bereits geladen", vbInformation, DialogTitle)
            Exit Sub
        Else
            oApp.Documents.CloseAll(True)
        End If


        ''''' !!!! Attention overwrites in local work directory

        '''''ToDo: aktivieren Aus Sicherung lesen
        ''''Cursor.Current = Cursors.WaitCursor

        '''''Juengste Sicherung suchen, zuweisen, entpacken
        '''''BasisCADModell
        ''''Dim SicherungCADBasisDateien As String
        ''''SicherungCADBasisDateien = JuengsteDatei(KonfigBasePfad, "*.7z")
        ''''Call SevenZipUnzip(SicherungCADBasisDateien, WorkPfad)
        '''''MessageBox.Show("entpacke" & Lf & SicherungCADBasisDateien & Lf & "nach" & Lf & WorkPfad)
        '''''KonfigsCADDateien
        ''''Dim SicherungCADKonfigDateien As String
        ''''SicherungCADKonfigDateien = JuengsteDatei(KonfigKonfigPfad, "*.7z")
        ''''Call SevenZipUnzip(SicherungCADKonfigDateien, WorkPfad)
        '''''MessageBox.Show("entpacke" & Lf & SicherungCADKonfigDateien & Lf & "nach" & Lf & WorkPfad)
        '''''VBAProjekt
        ''''Dim SicherungVBAProjekt As String
        ''''SicherungVBAProjekt = JuengsteDatei(KonfigVBAProjektSavePfad, "*.7z")
        ''''Call SevenZipUnzip(SicherungVBAProjekt, _KonfigVBAProjektPfad)
        '''''MessageBox.Show("entpacke" & Lf & SicherungVBAProjekt & Lf & "nach" & Lf & _KonfigVBAProjektPfad)

        ''''Cursor.Current = Cursors.Default


        'Load Inventor VBA-Projekt für Generierung und Speicherung der Varianten-CAD-Modelle
        If Not Lade_InvVBAProj(KonfigVBAProjektName, _KonfigVBAProjektPfad, DialogTitle) Then Exit Sub


        Try
            oApp.Documents.Open(CADModell, True) 'automatisierte Variante erzeugt manchmal Fehler bei anschließendem Schließen einer Datei -> Absturz Inventor
        Catch ex2 As Exception
            MsgBox("Beim Laden der Konfigurator Baugruppe ist ein Fehler aufgetreten" & vbCr &
                   "Bitte wenden Sie sich an ihren Administrator" & vbCr & vbCr &
                   "Fehlermeldung:" & vbCr & "Konfigurator Baugruppe öffnen: " & ex2.Message)
            Exit Sub
        End Try

        Call KonfiguratorSperren(KonfigMainPfad) 'creates textfile

        'Setzt Ansichtsdarstellung auf Standard
        oDoc = oApp.ActiveDocument
        Call oDoc.ComponentDefinition.RepresentationsManager.DesignViewRepresentations.Item("Standard").Activate

        Dim cam As Inventor.Camera = oApp.ActiveView.Camera
        cam.ViewOrientationType = ViewOrientationTypeEnum.kIsoTopRightViewOrientation
        cam.Apply()
		
		' open a ribbon tab
        Dim asmRibbon As Ribbon = g_inventorApplication.UserInterfaceManager.Ribbons.Item("Assembly")
        asmRibbon.RibbonTabs.Item("Company_Konfig").Active = True


    End Sub

 

Please excuse the english german mixed language in the code. I hope it's nevertheless understandable.

 

One of the main problems is that the error only somethimes occurs, so i can't fix it reliable.

 

I really hope on more ideas from you to get to the cause of the bug.

 

Many thanks in advance

 
 
 

 

0 Likes
Message 5 of 9

Anonymous
Not applicable
 Private Sub Wagen_Laden(WorkPfad As String, KonfigMainPfad As String, KonfigBasePfad As String, KonfigKonfigPfad As String, KonfigVBAProjektSavePfad As String, KonfigVBAProjektName As String, CADModell As String, DialogTitle As String)
        Dim oApp As Inventor.Application = g_inventorApplication
        Dim oDoc As Inventor.Document = oApp.ActiveDocument '''Try something here like oApp.ThisDoc.Document
0 Likes
Message 6 of 9

Anonymous
Not applicable

@Anonymous  thanks for your answer.

Could you please explain why do you think that oApp.ActiveDocument causes the error? I ask because i think that ThisDoc is used into iLogic rules to point to the doc that the rule contains.  But i will try it too as soon as the bug occurs.

0 Likes
Message 7 of 9

J-Camper
Advisor
Advisor

@Anonymous,

 

I'm trying to understand the process of this Sub Routine.  Please correct my assumptions if incorrect:

 

 

  • Stepping into Sub "Wagen_Laden", we are passed 8 Strings
  • Then we are setting a local ObjectVariable "oApp" as application to a Shared ObjectVariable from a Class "g_inventorApplication"
  • We get the active document as a generic document ObjectVariable
  • Then we have a If statement which has 2 options:
    • 1) Identify any number of open visible documents, sends message and terminates [returns out of sub]
    • 2) assume that means there are invisible documents, closes all "unreferenced documents" only, and proceeds further into sub  [This means we have closed all invisibly opened documents which are unreferenced by other documents, but any document that is invisibly opened and is Referenced will remain open.  This may or may not include "oDoc" ObjectVariable]
  • We should only continue the sub routine if [Option 2] is true
  • Now we make sure the correct VBA project is loaded, terminate if not
  • Now we try to open a document whose file path was passed to this sub routine
  • If the catch fails, I assume that means the passed string does not return a valid file path, and then terminates
  • We call a different sub routine, your comments says: "creates textfile"
  • Now we re-use a generic Document ObjectVariable to be this freshly opened document [I would probably define a new ObjectVariable for this step, but I don't know if this would cause your crash]
  • We activate a custom View Rep by name, then change the camera view
  • Finally we define a Ribbon using the Shared ObjectVariable for the application "g_inventorApplication", and activate it.

 

Can you verify this is the intended process of this sub routine? 

 

The bulk of this sub routine only runs when called from an invisibly open document?

 

At no point is the opened document saved after changes are made, but maybe that happens in a different sub routine?

 

Maybe the error occurs when called from an invisibly open document that is referenced, because you do end up re-using the "oDoc" ObjectVariable to open a document.  If it doesn't get cleared, that may be causing the issue?

 

 

0 Likes
Message 8 of 9

Ralf_Krieg
Advisor
Advisor

Hello

 

As I understand you "open" one of the part documents of your assembly in a separate window (a separate view). If you close this document (you close the view in fact) the view must be the active view. Otherwise Inventor becomes unresponsive and crashes after a few seconds.


R. Krieg
RKW Solutions
www.rkw-solutions.com
0 Likes
Message 9 of 9

Anonymous
Not applicable

Hello

 

@J-Camper

you're wrigth with describing the intends of this code.


@J-Camper  schrieb:

 

...
  • Then we have a If statement which has 2 options:
    • 1) Identify any number of open visible documents, sends message and terminates [returns out of sub]
    • 2) assume that means there are invisible documents, closes all "unreferenced documents" only, and proceeds further into sub  [This means we have closed all invisibly opened documents which are unreferenced by other documents, but any document that is invisibly opened and is Referenced will remain open.  This may or may not include "oDoc" ObjectVariable] ...

The sub only steps further if there are no visible documents opened. So odoc is nothing and can never include other referenced documents. This is only to make sure Inventor has no opened documents in the background.

 

The sub can be started from each document or zeroDocs but ends with a message if not started from zeroDocs.

 

There are no changes made to the assembly an no saving operations

 

The error occurs also from a new started Inventor session so i don't think an invisibly open document affects it.

 

@Ralf_Krieg 

Hi i think we know us from a german board were i described the issue too.

Yes after succesfully processing the sub the assembly is open visible, i open a part document manually and close (the view) manually. After this sometimes Inventor becomes unresponsive and crashes. For this behavior are no other api calls needed, but if i use the api close command its result in same error.

 

 

On a PC were the addin never before was loaded and the assymbly never befor was opened the error occurs until I manually open and close the .iam once. Unfortunally i have no untouched PC to the hand at the moment.

 

Regards

e.beul

 

0 Likes