Document.Close method not working after UserForm event CALL

Document.Close method not working after UserForm event CALL

karolis.s
Advocate Advocate
212 Views
1 Reply
Message 1 of 2

Document.Close method not working after UserForm event CALL

karolis.s
Advocate
Advocate

Hello, looking for help to understand why Document Class Close method not working. It is called, but documents remain still opened and I can't change my project until I reboot Inventor Application.

 

Here is mine main function

 

Debug.WriteLine("All docs: " & InvApp.Documents.Count)
Debug.WriteLine("Visible documents: " & InvApp.Documents.VisibleDocuments.Count)

Dim oDocs As Documents = InvApp.Documents,
    visibleDocs = InvApp.Documents.VisibleDocuments,
    visibleDocsList As New List(Of String)

For Each oDoc As Document In visibleDocs
    visibleDocsList.Add(oDoc.FullFileName)
Next

For Each oDoc As Document In oDocs
    If Not visibleDocsList.Contains(oDoc.FullFileName) Then
        oDoc.Close()
    End If
Next

Debug.WriteLine("After close docs: " & InvApp.Documents.Count)

 

Here is event handler

 

Private Sub manufacturing_radio_btn_CheckedChanged(sender As Object, e As EventArgs) _
        Handles manufacturing_radio_btn.CheckedChanged
            
    If manufacturing_radio_btn.IsHandleCreated Then

        exportMfc = manufacturing_radio_btn.Checked
            
        DataGridView.Rows.Clear()
        DataGridView.Columns.Clear()

        AddColumns()
        AddRows()

    End If

End Sub

 

AddColumns function just take valid formats from my main class.

AddRows function Loops through each .idw file in given directory, opens it and sends to me valid sheets.

 

And again if event handler is not called, documents are closed properly, otherwise they remain open.

 

0 Likes
213 Views
1 Reply
Reply (1)
Message 2 of 2

dalton98
Collaborator
Collaborator

Maybe try redefining the document before trying to close it? 

Dim oDocs As DocumentsEnumerator = ThisApplication.Documents.VisibleDocuments

For Each oDoc As Document In oDocs
	oDoc = ThisApplication.Documents.open(oDoc.FullDocumentName, True)
	oDoc.Close
Next
0 Likes