Save As - Updates all Open Files?

Save As - Updates all Open Files?

Curtis_Waguespack
Consultant Consultant
1,203 Views
7 Replies
Message 1 of 8

Save As - Updates all Open Files?

Curtis_Waguespack
Consultant
Consultant

I have an assembly the contains one part, and a drawing that contains one view of that assembly and one view of that part. 

 

I have an iLogic rule in the part and basically the same rule in the assembly, that will do a "Save As" on the part to create a new file.

 

When I do this from the part, somehow the part is replaced in the open assembly and the open drawing, even though the rule in the part is not looking at anything other than the part file document.

 

When I do this from the assembly, I expect it to update the part in the assembly. But it actually replaces the part file in the drawing view with the new part file also, even though the iLogic is not looking at the drawing.

 

So it appears the the Save As magically replaces the old file with the new file in all open documents that reference it.

 

I've attached a simple data set here. The files are Inventor 2015 files.

 

Questions:

Why does this happen?

And is there a way to prevent this?

 

Thanks in advance,

Curtis

 

The code is pretty basic, for the part rule it is this:

 

NewFileName =  "Cube_ " & TimeString 'add prefix
NewFileName = Replace(NewFileName,":", ".") 'remove colons, replace with periods

'do save as
ThisDoc.Document.saveas(ThisDoc.Path & "\" & NewFileName &  ".ipt" ,False)
MessageBox.Show("New File: " & ThisDoc.Path & "\" & NewFileName &  ".ipt", "iLogic")

For the assembly it is this:

 

Dim refDoc As Document

For Each refDoc in ThisDoc.Document.AllReferencedDocuments

	NewFileName =  "Cube_ " & TimeString 'add prefix
	NewFileName = Replace(NewFileName,":", ".") 'remove colons, replace with periods
	'do save as
	refDoc.saveas(ThisDoc.Path & "\" & NewFileName &  ".ipt" ,False)
	MessageBox.Show("New File: " & ThisDoc.Path & "\" & NewFileName &  ".ipt", "iLogic")

Next

 

 

SaveAs1.JPG

 

SaveAs2.JPG

 

 

 

SaveAs3.JPG

 

 

SaveAs4.JPG

 

 

 

EESignature

0 Likes
Accepted solutions (1)
1,204 Views
7 Replies
Replies (7)
Message 2 of 8

smilinger
Advisor
Advisor

I might be wrong, but I think you should use SaveCopyAs instead of SaveAs:

 

ThisDoc.Document.saveas(ThisDoc.Path & "\" & NewFileName &  ".ipt" ,True)

refDoc.saveas(ThisDoc.Path & "\" & NewFileName &  ".ipt" ,True)
0 Likes
Message 3 of 8

Curtis_Waguespack
Consultant
Consultant

Hi smilinger,

 

Hey, thanks for the reply.

 

So in my case I want to use SaveAs (False) rather than SaveAs (True), due to the context of how I'm using this. Meaning that I need to have the new file loaded after the SaveAs, because I have more tasks to perform on that new file.

 

My concern is that since I can not predict which files a user might have open when they use this tool, that the SaveAs is going to replace the old part with the new part, in an assembly or drawing, without the user realizing it.

 

I'm puzzled as to how / why doing a SaveAs on a part file automatically updates every open document that references that part file.

 

Thanks again,

Curtis

EESignature

0 Likes
Message 4 of 8

smilinger
Advisor
Advisor
Think of the path and name of the part document as a property. When you call saveas it only change this property of the document in the memory. In the meantime this document is also referenced by other documents in the memory. So for the other files referencing this part it looks like changing an iproperty of the part.

Also think about what is happening when you are creating a new document, the document is first created in the memory, then when you click save the file name is given to the document as if it is an iproperty.

Just my thoughts.

And it is more confusing if you realize that if you literally click Save As in inventor it behaves differently with the API.
Message 5 of 8

Curtis_Waguespack
Consultant
Consultant

@smilinger wrote:

And it is more confusing if you realize that if you literally click Save As in inventor it behaves differently with the API.

I think you're likely correct in all of this, but I hope not. Smiley Wink

 

Because I don't want it replacing references in other files when the code does not instruct it to do so. Smiley Frustrated

 

The way it behaves when clicking Save As is what I expected and what I need it to do. I was hopeful that maybe there was some option, trick, or magic words to get the expected results.

 

Thanks again for the reply,

Curtis

EESignature

0 Likes
Message 6 of 8

Curtis_Waguespack
Consultant
Consultant

bump

EESignature

0 Likes
Message 7 of 8

wayne.brill
Collaborator
Collaborator
Accepted solution

Hi Curtis,

 

There is not a way to change the behavior of SaveAs other than the SaveCopyAs  Boolean parameter. It looks like neither True or False for this parameter gives you the behavior you want.

 

Maybe there is another way to meet your requirement. Not sure if this will do that but here is an update to the part rule that use True for the SaveCopyAs parameter and then just opens up the new part that was created. 

NewFileName =  "Cube_ " & TimeString 'add prefix
NewFileName = Replace(NewFileName,":", ".") 'remove colons, replace with periods

'do save as
'ThisDoc.Document.saveas(ThisDoc.Path & "\" & NewFileName &  ".ipt" ,False) 'WB commented

ThisDoc.Document.saveas(ThisDoc.Path & "\" & NewFileName &  ".ipt" ,True) 'WB added

'WB added
ThisApplication.Documents.Open(ThisDoc.Path & "\" & NewFileName &  ".ipt")

MessageBox.Show("New File: " & ThisDoc.Path & "\" & NewFileName &  ".ipt", "iLogic")

 

 

 

Here is a rule to try for the assembly. It also does a SaveAs with the SaveCopyAs parameter as True but then replaces the reference for that part with the saved part.

 

Dim refDoc As Document

	Dim refDocDesc As DocumentDescriptor
	Dim refFileDesc As FileDescriptor

	For Each refDocDesc In ThisDoc.Document.ReferencedDocumentDescriptors
		NewFileName =  "Cube_ " & TimeString 'add prefix
		NewFileName = Replace(NewFileName,":", ".") 'remove colons, replace with periods
		
		refDoc = refDocDesc.ReferencedDocument
		refDoc.SaveAs(ThisDoc.Path & "\" & NewFileName & ".ipt", True)
		
		refFileDesc = refDocDesc.ReferencedFileDescriptor
		refFileDesc.ReplaceReference(ThisDoc.Path & "\" & NewFileName & ".ipt")
		
		ThisApplication.Documents.Open(ThisDoc.Path & "\" & NewFileName &  ".ipt")
		
		MessageBox.Show("New File: " & ThisDoc.Path & "\" & NewFileName &  ".ipt", "iLogic")
	Next

 

 

 

Thanks,

Wayne



Wayne Brill
Developer Technical Services
Autodesk Developer Network

0 Likes
Message 8 of 8

Curtis_Waguespack
Consultant
Consultant

Hi wayne.brill,

 

Thanks for looking into this. I won't get back to this for a while, but when I do I'll give your examples a go.

 

Thanks again,

Curtis

 

 

EESignature

0 Likes