What's the right procedure to close an invisible document

What's the right procedure to close an invisible document

Anonymous
Not applicable
2,159 Views
9 Replies
Message 1 of 10

What's the right procedure to close an invisible document

Anonymous
Not applicable

Hi,

 

I open a document in invisible through api, something like

var partDoc = (PartDocument)_invApp.Documents.Open(MyFile, false);

.....do operations

partDoc.Close(true);

 

But it seems that the file is still opened because I can not delete the lock file.  If I close Inventor I'm still not able to delete the lock file because there is another Inventor process running. I have to end the Inventor process from task manager then I can delete the lock file. Is it something wrong?

 

0 Likes
Accepted solutions (3)
2,160 Views
9 Replies
Replies (9)
Message 2 of 10

JhoelForshav
Mentor
Mentor

Hi @Anonymous 

Have you tried ReleaseReference before closing the document? 🙂

partDoc.ReleaseReference
partDoc.Close(True)

But what do you mean that there's another inventor process running? is your code opening multiple instances of inventor?

Message 3 of 10

dtimm8RCUM
Contributor
Contributor
Accepted solution

I ran into a similar problem, where what I started calling "phantom" documents would remain open when I created a new part from a template. The number of loaded documents wouldn't be equal to the number of documents I could see.

 

In your case, simply going though and closing all of the loaded documents might fix your issue. (In my case, I had to close the last document in the Documents Collection.)

 

For i as Integer = 1 to invApp.Documents.LoadedCount
    invApp.Documents.Item(i).Close()
Next i

 

 

Message 4 of 10

WCrihfield
Mentor
Mentor
Accepted solution

Something is not normal if you can't get rid of a reference to a document, even after you have closed Inventor.

Here's another way to make sure you have closed all documents that have been opened 'invisibly'.

It works well with the line that Jhoel provided, because we both used the same techniques on other similar posts very recently.

oDoc.ReleaseReference
ThisApplication.Documents.CloseAll(True)

When you use these two tools together, it should close all of those pesky invisibly opened documents.

Use the 'ReleaseReference' immediately after you don't need an invisibly opened document anymore (before you exit whatever loop or code block you opened the document in).  Then near the end of the code, use the CloseAll(True), to close any other missed invisibly open documents.

Note:  Some documents may be either open or 'initiated' in the background as a result of having an assembly or other similar document open.  Unless you only partially open an assembly, it must load most (if not all) of the contained documents into memory (one way or another).  (Part document containing linked derived parts may also have loaded the source of the derived part model in memory, that you may not be able to close, without first closing the a main part containing the link.)

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

Message 5 of 10

Anonymous
Not applicable

I tried both 

For i as Integer = 1 to invApp.Documents.LoadedCount
    invApp.Documents.Item(i).Close()
Next i

and

oDoc.ReleaseReference
ThisApplication.Documents.CloseAll(True)

But the problem is still there. The part has derived components referenced to other files.

I checked the document number, it has only 1. I don't see any other invisible documents.

If I close Inventor, it automatically creates another invisible Inventor process in task

manager with similar memory size. I have to end the Inventor process then I can delete

the lock file. If I open the part document visibly, There is no problems, but much slow.

0 Likes
Message 6 of 10

WCrihfield
Mentor
Mentor
Accepted solution

OK. So something else is definitely going on then.

Are you using any sort of external or stand-alone application (.exe) that is designed to integrate with or share resources with your Inventor application?  Do you maybe have an Excel document or XML file open that an Inventor document was referencing for its Parameters or iProperties (or other data)?  Are you allowing plenty of time for all of the closed documents to save to whatever network locations or Vault they may be sourced from, to make sure your processor isn't still dealing with them in that kind of way?

I'm just throwing out some thoughts of the top of my head, in an attempt to hopefully trigger some other ideas as to what may be causing this.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

Message 7 of 10

J-Camper
Advisor
Advisor

The snippet you posted should work fine so I don't know what is causing the issue, posting more of the code might help figure that out.

 

But if opening it visibly works without issue, you could turn off the ScreenUpdating while working in the Document, which should give a similar result in terms of speed.  You will want some kind of error handling to turn ScreenUpdating back on if the rule fails before closing the document:

 

On Error GoTo Here
ThisApplication.ScreenUpdating = False
Dim Doc As PartDocument = ThisApplication.Documents.Add(kPartDocumentObject, , True)
'Do Stuff
MessageBox.Show("Message", "Title")

Doc.Close(True)
ThisApplication.ScreenUpdating = True

Exit Sub

Here: ThisApplication.ScreenUpdating = True

 

Message 8 of 10

Anonymous
Not applicable

Hi WCrihfield,

After moving the drawings from network drive to my local drive, the lock files automatically go away.

All Jhoel, dtimm8RCUM and yours solutions work. I didn't think it's a network related issue.

 

I'm developing a stand-along plug-in application(.exe) and use Apprentice for showing preview image.

 

Thank you so much!

0 Likes
Message 9 of 10

NachoShaw
Advisor
Advisor

Hey

 

Are you using 2020 by chance? i have had this issue for a while and tried all of the suggestions. weird thing is, i only get this issue with 2020 closing but then leaving an invisible document open. Sometimes i can simply open then close 2020 without having any documents opened and i still get the issue. 2019 & 2021 with the exact same code & assembly do not have this problem

 

Thanks

 

Nacho
Automation & Design Engineer

Inventor automation Programmer (C#, VB.Net / iLogic)
Furniture, Sheet Metal, Structural, Metal fab, Tradeshow, Fabrication, CNC

EESignature


Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.


0 Likes
Message 10 of 10

Anonymous
Not applicable

Hi NachoUK,

I use Inventor 2017. The network related issue actually caused by the referenced files. I copied the folder from 

my local drive to network drive, when I open the document from the network drive, the referenced files still point 

to my local drive, and the network drive was pretty slow. After I changed the project file, the issues went away.

Remember call "ReleaseReferences" before you close the document.

0 Likes