Problem with unspecified error while creating drawing files.

Problem with unspecified error while creating drawing files.

SMillsYS3X2
Advocate Advocate
264 Views
3 Replies
Message 1 of 4

Problem with unspecified error while creating drawing files.

SMillsYS3X2
Advocate
Advocate

I have a code that is making several drawing files while it runs, and I am having a problem with it erroring and not actually saving them. It doesn't happen all the time, but I think it has something to do with inventor keeping a file active in the background even after a rule has run. That is to say, it's keeping the rights to it so the file manager can't overwrite or delete it, and so causing this error when it tries.

 

Is there any way to clear/close all background files that Inventor has at that moment without stopping and re-starting Inventor and closing active and open files? Or some way of checking that before trying to write-over a locked file?

Image of the error:

SMillsYS3X2_0-1771277392091.png

 



0 Likes
Accepted solutions (1)
265 Views
3 Replies
Replies (3)
Message 2 of 4

Curtis_W
Consultant
Consultant
Accepted solution

@SMillsYS3X2 

Is it closing the file that the rule is run from? If so that will cause an error, as iLogic is document based and needs to keep the "calling" document open.

I have also run into issue with a routine that hits read only files on the save and can not save them, which causes them not to close.

You might resolve these situations with something like this:

For Each oDoc As Document In ThisApplication.Documents

	If oDoc Is ThisDoc.Document Then Continue For

	Dim fileInfo As New System.IO.FileInfo(oDoc.FullFileName)
	If fileInfo.IsReadOnly Then fileInfo.IsReadOnly = False

	Try
		oDoc.Save
	Catch ex As Exception
		Logger.Info(ex.Message)
		'	MsgBox(ex.Message)
	End Try


	Try
		oDoc.Close
	Catch ex As Exception
		Logger.Info(ex.Message)
		'	MsgBox(ex.Message)
	End Try

Next




I also sometimes use something like this at the beginning of a routine to close all but the active file :

	For Each doc As Document In ThisApplication.Documents
		If doc IsNot ThisDoc.Document Then doc.Close(False)   ' False = do NOT save		
	Next

	ThisApplication.CommandManager.ControlDefinitions.Item("iLogic.FreeILogicMemory").Execute


Hope that helps, 
Curtis

EESignature

Message 3 of 4

SMillsYS3X2
Advocate
Advocate

I think the second part is what I need.

 

First part of the code creates, then opens several files in the background with (segments of the code);

 

Dim oDWGList As New List(Of DrawingDocument)
oDWGList.Add(ThisApplication.Documents.Open(oPath,False))
For Each oDWG In oDWGList
   oDWG.Save
   oDWG.Close
Next

But sometimes it errors, and leave some of these documents open in the background. That is why I think it sometimes errors on the second run.

0 Likes
Message 4 of 4

WCrihfield
Mentor
Mentor

Another factor in this case could be that you are storing the Documents within a List, and not removing them from that List when you are done with them.  Maybe try including a line like:

oDWGList.Remove(oDWG)

within that loop, but just before calling the oDWG.Close method.  Maybe you could also use the built-in method Documents.CloseAll.  That method has an Optional Boolean type input parameter which we can use to specify that we only want it to clear out all unreferenced documents too, which I often use when batch processing a lot of files, to help clear out the documents from Inventor's memory.  Just a couple more tips that may help in the future.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)