That number in the lower right corner of the screen can be a little unpredictable. Sometimes you have to update the document, before the number in the corner of the screen will be updated after using one of these techniques.
When you open a document invisibly (in the background) using this process:
Dim oDoc As PartDocument = ThisApplication.Documents.Open("C:\\Temp\Part3.ipt",False)
, it does not seem to add to the total number of open documents.
However when you create a new document like this:
Dim oDoc As PartDocument = ThisApplication.Documents.Add(DocumentTypeEnum.kPartDocumentObject, , False)
(which is also 'invisible'), it does add it to the total number of open documents.
There are several other scenarios that can leave behind invisible and/or 'unreferenced' documents too.
Here are a couple tools available to help clean up those documents, which are invisibly open in the background, to help free up system memory & help performance in high number situations.
You can release the reference to an invisible document, as long as it is, in fact, not being referenced by anything.
oDoc.ReleaseReference
You can also use this following line to close all invisible unreferenced documents that may be in memory. When you specify True, it releases all the unreferenced documents, and when you specify False, it works like normal to close all regular open documents.
ThisApplication.Documents.CloseAll(True)
Here is a simple iLogic rule to test this, that incorporates all the above code. To test the Add technique, un-comment that first line, then comment out the secont (Open) line, then run the rule. Then reverse the commented lines to test the Open line. Of course you may have to change the path and file name of the part is attemting to open.
'Dim oDoc As PartDocument = ThisApplication.Documents.Add(DocumentTypeEnum.kPartDocumentObject, , False)
Dim oDoc As PartDocument = ThisApplication.Documents.Open("C:\\Temp\Part3.ipt",False)
ThisApplication.ActiveDocument.Update
MsgBox("ThisApplication.Documents.Count = " & ThisApplication.Documents.Count & vbCrLf & _
"Check the number in the lower right corner of the Inventor screen to see if this is the same.",vbOKOnly," ")
'oDoc.Close(True) 'skip save
oDoc.ReleaseReference
ThisApplication.Documents.CloseAll(True)
MsgBox("ThisApplication.Documents.Count = " & ThisApplication.Documents.Count & vbCrLf & _
"Check the number in the lower right corner of the Inventor screen to see if this is the same.",vbOKOnly," ")
If this solved your problem, or answered your question, please click ACCEPT SOLUTION.
Or, if this helped you, please click 'LIKE' 👍.
If you have time, please... Vote For My IDEAS 💡and Explore My CONTRIBUTIONS
Inventor 2021 Help | Inventor Forum | Inventor Customization Forum | Inventor Ideas Forum
Wesley Crihfield

(Not an Autodesk Employee)