Documents.Open Method

Documents.Open Method

DonStauffer99
Advocate Advocate
1,257 Views
4 Replies
Message 1 of 5

Documents.Open Method

DonStauffer99
Advocate
Advocate

To me, opening something on a computer means reading it from disk into memory, and possibly displaying it.

"The Document collection object contains all in-memory Inventor documents." (presumably it's a typo that it doesn't say "Documents").

So, what exactly does the Documents.Open Method? I know, it "opens" a document, but since this collection is already "in-memory...documents", it can't mean "bring it into memory". And since the method has an option to open it as "visible" (or "invisible", presumably), it can't mean to display the document on screen.

What does that leave? I can't figure it out. What does "Open" do? Is there some meaning besides "bring into memory and display"? Why would you ever want to bring something into memory that's already in memory? When would you use this method? Sounds like a weird question, but it seems unclear to me.

Under what circumstances might a second document referenced in a first document not be in memory if the first one is? If a document isn't in memory, how could you get it in memory if the Documents collection (and its Open method) only apply to documents already in memory?

How does this work? I don't get it from the documentation.

0 Likes
1,258 Views
4 Replies
Replies (4)
Message 2 of 5

WCrihfield
Mentor
Mentor

Hi @DonStauffer99.  The 'Documents.Open' method can certainly be complex to understand fully.  It can be used to 'visibly' show a document that is already open invisibly, such as the documents that get automatically initialized (invisibly, partially loaded into Inventor's session memory) when you open things like drawings or assemblies in Inventor.  If you have Inventor's status bar visible, you will usually see those numbers at the right end of that status bar...one representing the number of 'occurrences', while the other represents the total number of 'open' documents (both visible & not visible).  But it can also be used to initially open a file, which creates the Document by loading the data from the file into Inventor's session memory, which can either be done visibly, or invisibly.  If a document is opened invisibly, we can also make it visible by adding an 'Inventor.View' to Inventor for that document, though the Document.Views.Add method, because its Document.Views.Count property will be zero before that.  If a file was directly and invisibly opened to create a Document, and nothing else is referencing that document, then we can just use its ReleaseReference method when done with it, instead of its Close method, because there are no Views to close.  If we close the only View of a Document, and there are no other references to that Document, then that action will also usually close that document, and release Inventor's reference to it.  After all views and references have been eliminated for a Document, Inventor's built-in 'trash collector' will clear it from Inventor's memory at some point soon after, freeing up that space in memory.  So, the Open method can almost be thought of similar to the Add method, as far as the Documents collection is concerned, when opening directly from a File, and not through any 'referenced files/documents' of some other open document, because it does not already exist within the Documents collection yet.  There is a similar situation with the FileManager.Files property, that sounds like a paradox, because how can Inventor's FileManager possibly know about every Inventor 'File' in your whole file system...where it likely means only the 'Files' that are associated with some of the Documents that are currently open/loaded in Inventor's session memory that have either been saved, or opened from an existing file (not New documents, because no File yet).

Closing documents is probably even more complicated, because sometimes doing so will just eliminate any 'Views' of that Document, without wiping that Document out of Inventor's session memory, or can leave it invisibly open.  It all depends on how and why the document was initially opened, and if any other open documents are still referencing it in any way, or if any code-based resources still have a reference to it.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes
Message 3 of 5

hollypapp65
Advocate
Advocate

After IV start, there is no "opened" file.

The Documents collection does contain all pointers to all opened documents.

It just empty and return nil until a file is opened.

 

"All documents" does include "no document".

 

Once a document is opened, you don't need to use "Open" to access it.  You can check if the file is in the collection.

0 Likes
Message 4 of 5

DonStauffer99
Advocate
Advocate

Thanks for the copious details! Useful stuff.

0 Likes
Message 5 of 5

WCrihfield
Mentor
Mentor

Below are a few other Links to online help pages about related 'Events', which often contain 'Remarks' sections which can also be enlightening.

ApplicationEvents.OnInitializeDocument 

ApplicationEvents.OnOpenDocument 

ApplicationEvents.OnNewDocument 

ApplicationEvents.OnActivateDocument 

ApplicationEvents.OnTranslateDocument 

ApplicationEvents.OnDeactivateDocument 

ApplicationEvents.OnCloseDocument 

ApplicationEvents.OnTerminateDocument 

ApplicationEvents.OnUndoOpenDocument 

Some of these events have 'parallel' events defined under the DocumentEvents object, which obtained directly from an existing Document object, which are often easier to use, and are limited to just that one document, instead of all documents in Inventor.  There were others also, but these likely provide enough insight.

Document.DocumentEvents 

 

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes