Documents Close All function not working in Invento 2024?

Documents Close All function not working in Invento 2024?

pball
Mentor Mentor
234 Views
4 Replies
Message 1 of 5

Documents Close All function not working in Invento 2024?

pball
Mentor
Mentor

I'm running Inventor 2024.3.3 and my function to close unreferenced documents doesn't work. That function is the one line below and it is not closing documents.

 

ThisApplication.Documents.CloseAll(True)

 

From the VBA immediate window running this line shows Inventor having 67 documents loaded, with zero visible documents open. Previously running the close all with true parameter would cause that number to be zero.

 

debug.Print thisapplication.Documents.Count

Check out my style edits for the Autodesk forums
pball's Autodesk Forum Style
0 Likes
235 Views
4 Replies
Replies (4)
Message 2 of 5

WCrihfield
Mentor
Mentor

Surprisingly, I can confirm that behavior.  I am using that exact same version of Inventor, and just did a test with a couple simple internal iLogic rules and found the same results.  I used a For i = 1 To 5 type loop to 'create/add' 5 New part documents with Visible = False, then did nothing with them at the end of the rule, which leaves them open, but no document tabs (shows in count in Inventor's status bar).  I did that twice, which showed a total of 12 open documents, because I already had two others open visibly.  Then I ran a rule that checked count directly from Documents object both before and after calling that method, where both messages showed the same number, followed by another For Each type loop of all Documents, which checked if they had at least one View, and if not, uses their 'Close(True') method, and another message after that showing the total again, which was finally reduced to 2 Documents (the two that were visible - had document tabs showing).

No assemblies or drawings involved, so nothing was 'referencing' them.

 

Edit:  After a little more testing, I found that if we used the Document.ReleaseReference method on those Document objects that we opened invisibly after done with them, then the total number of open documents is still recognized after creating the new ones, but that number is properly reduced by the CloseAll(True) method afterwards.  Because of this, I am not sure if this is a bug in Inventor's behavior or not.  But maybe @MjDeck could confirm if that is correct or not.  And if what we initially saw is not normal / expected behavior, he may be able to get it looked into for us.

Below is an example iLogic rule I used for testing this behavior with.  When Line 7 is commented, the total is not reduced by CloseAll(True), but if uncommented, it appears to work as expected.

 

Dim oInvApp As Inventor.Application = ThisApplication
Dim oDocs As Inventor.Documents = oInvApp.Documents
Dim oDoc As Inventor.Document = Nothing
Logger.Info("Docs Count Before Creating 5 New Ones = " & oDocs.Count)
For i As Integer = 1 To 5
	oDoc = oInvApp.Documents.Add(DocumentTypeEnum.kPartDocumentObject, Nothing, False)
	'oDoc.ReleaseReference() '<<< this makes the difference when uncommented >>>
Next
Logger.Info("Docs Count After Creating 5 New Ones = " & oDocs.Count)
oDocs.CloseAll(True)
Logger.Info("Docs Count After Using CloseAll(True) = " & oDocs.Count)
For Each oDoc In oDocs
	If oDoc.Views.Count = 0 Then
		Try : oDoc.Close(True) : Catch : End Try
	End If
Next
Logger.Info("Docs Count After Closing Each With No Views = " & oDocs.Count)

 

 

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

Message 3 of 5

pball
Mentor
Mentor

@WCrihfield  Thanks for sharing all of that.

 

To provide more details for anyone that looks into this. I was not creating, opening, or closing parts with code. I have been adding and removing parts from an assembly manually. Another note is after I closed all visible documents there were 107 documents by checking thisapplication.Documents.Count. After running thisapplication.Documents.CloseAll(True) that number did not change.

Check out my style edits for the Autodesk forums
pball's Autodesk Forum Style
Message 4 of 5

MjDeck
Autodesk
Autodesk

@WCrihfield , your rule is working as expected. If you are holding a reference to a document through the API, then Inventor will not close that document as if it was unreferenced.

@pball , can you give more details about your workflow? Do you have model states in your parts or assemblies? Does the open document count show up in the very bottom right hand corner of the Inventor window? (For instance, when I start Inventor it shows 0  0. If I create a new part it shows 1  1.) Or do you see them only through the API?


Mike Deck
Software Developer
Autodesk, Inc.

0 Likes
Message 5 of 5

pball
Mentor
Mentor

@MjDeckI do not recall what the counter in Inventor showed yesterday but that 100+ documents count was from the API after all visible documents were closed.

 

I played around a bit today and opening an assembly showed 24 unique parts, adding a different brought that up to 25, then deleting that same part it remained at 25, which is expected. After running the close all command the count did go down to 24. So it seems I cannot give steps to reproduce this yet. Yesterday when I was working I was opening and closing multiple assemblies through out the day.

Check out my style edits for the Autodesk forums
pball's Autodesk Forum Style
0 Likes