Compare old and new file names after Save As

Compare old and new file names after Save As

Nejc.Leban
Advocate Advocate
2,497 Views
32 Replies
Message 1 of 33

Compare old and new file names after Save As

Nejc.Leban
Advocate
Advocate

Hi everyone.

I would like to change some values in a document when it is saved as new file, either with Save As or Save&Replace. Let's say, I have an assembly named 12345-00-000-00 it is checked into vault and is read-only. I then save it as new file named 54321-00-000-00 to create a new product. After it saves it as a new file, I would like to automatically (without pressing any other button or running a rule manually other than Save As or Save&Replace) change the Author and Designer to current User: 

ThisApplication.ActiveDocument.PropertySets.Item("Inventor Summary Information").Item("Author").Value = ThisApplication.GeneralOptions.UserName

 Does anyone know how one would get this to work?

 

Best regards,

Nejc

 

 

0 Likes
Accepted solutions (4)
2,498 Views
32 Replies
Replies (32)
Message 21 of 33

yuzeaa
Advocate
Advocate

I am unable to reproduce your problem,I  insert Frame on  two lines with same length and no error came out.Can you upload your Inventor file?(Inventor 2020)   or   provide  more detailed description

0 Likes
Message 22 of 33

Nejc.Leban
Advocate
Advocate

I'm using Inventor 2021, so I can only give you the step file. I hope you can work with that, but I don't think you'll have issues if you didn't have them when you tried on your own file. Do you think Inventor version might be the problem?

0 Likes
Message 23 of 33

Nejc.Leban
Advocate
Advocate

Actually, I tried it again and it's not only with same length lines, creating multiple length frame parts at the same time shows the same error.

0 Likes
Message 24 of 33

Nejc.Leban
Advocate
Advocate

I uncommented the Msgbox, to try and see where the problem is when inserting frame parts and I get this message:

C:\Designs\Assembly1\Frame\DIN EN 10219-2 012487 163468979.ipt was saved as
C:\Users\...\AppData\Local\Temp\v3#00c546b-dsa5....ipt

 

I then get the same error as I posted earlier - A frame member could not be created. The template file... could not be located in CC library.

After that, I try to insert multiple frame members again and then it works...

 

0 Likes
Message 25 of 33

yuzeaa
Advocate
Advocate

I don't think the issue is caused by the version of Inventor. You can try to debug the code by yourself. Commenting the code line by line to find which line cause the problem.After modifying the code, remember to restart the inventor each time

微信图片_20230523150747.png

 

By the way,you don't need to set the rule run before save. setting it with both "new file" and "open file"  is more appropriate.Once the ilgoic fired once ,it works like addin and not need to run again.

 

 

Message 26 of 33

yuzeaa
Advocate
Advocate
Accepted solution

Try to insert this line to your code 

微信图片_20230523155817.png

Dim newname As String = Context(0)
If newname.Contains("AppData") Then Exit Sub
Message 27 of 33

Nejc.Leban
Advocate
Advocate

I owe you a beer or two. Thanks! Works perfectly.

0 Likes
Message 28 of 33

yuzeaa
Advocate
Advocate
Accepted solution

Sorry I forgot to reset "isSaveAS" to "Fasle" before "exit sub"

微信图片_20230523162229.png

Dim newname As String = Context(0)
If newname.Contains("AppData") Then 
   isSaveAS = False
   Exit Sub
End If

 

Message 29 of 33

Nejc.Leban
Advocate
Advocate

Hey @yuzeaa,

 

Your code has been working mostly like I would like it to work, but me and my colleagues have some issues in certain scenarios, where the code copies a property when it shouldn't.

 

I have an assembly with a sheet metal part and a standard content center part.

The Assembly and sheet metal part are saved in C:\Workplace\Designs\10695\,

the standard CC part is saved in C:\Workplace\Content Center Files\en-US\.

 

I saved the assembly and both parts, created the drawing and checked in everything into vault. The assembly had a value stored in iProperties Custom, let's say IDnumber = 123456.

 

I then wanted to make modifications to the assembly - I had to change the length of the standard CC part. When I changed the length and saved the assembly, the IDnumber from the iProperties got copied from Custom to Comments.

I wouldn't want this to happen, unless I save the Assembly as a new file. In this case, the assembly wasn't saved as a new file, the only thing that changed was the length of the CC part.

 

I have added a statement which checks if the saved part is in the content center folder:

ElseIf newname.Contains("Content Center Files") Then
				isSaveAS = False		'reset False
				Exit Sub
			End If

(Edit: the added statement makes the code work as I want it to)
... but I would like to know why this happens, if you know and can explain it to me.

Thanks!

 

0 Likes
Message 30 of 33

yuzeaa
Advocate
Advocate

@Nejc.LebanSorry, I wasn't able to see your reply that mentioned me. I'm not very clear about the reason for your problem,but I have simplified the code, can you please try it again?

Class ThisRule
Private WithEvents oApplicationEvents As ApplicationEvents
Dim tempDir As String 
Sub Main
	If SharedVariable.Exists("ApplicationEvent") Then Return
	oApplicationEvents = ThisApplication.ApplicationEvents
	sharedVariable("ApplicationEvent") = oApplicationEvents
	tempDir = IO.Path.GetTempPath() 
End Sub
Private Sub oAPP_onsave(DocumentObject As Document,
                        BeforeOrAfter As EventTimingEnum,
						Context As NameValueMap,
						ByRef HandlingCode As HandlingCodeEnum) _
						Handles oApplicationEvents.OnSaveDocument
    If BeforeOrAfter = EventTimingEnum.kBefore Then Return
	If Context.Name(1) = "SaveCopyAsFileName" OrElse DocumentObject.FileSaveCounter = 1 Then
		If IO.Path.GetDirectoryName(context(0)) = tempDir Then Return
	'	Dim doc = ThisApplication.Documents.Open(Context(0), False)
		Dim doc = ThisApplication.Documents.Cast(Of Document).First(Function(x) x.FullDocumentName = Context(0))
		doc.PropertySets("Inventor Summary Information")("Author").Value = ThisApplication.GeneralOptions.UserName 
	    doc.PropertySets("Design Tracking Properties")("Creation Time").Value = DateString
    End If
End Sub
End Class

 

0 Likes
Message 31 of 33

Nejc.Leban
Advocate
Advocate

Hi @yuzeaa .

It's not a problem, I'm not in a hurry. The modification I made works now.

I tried the code, but nothing happens.

 

0 Likes
Message 32 of 33

Nejc.Leban
Advocate
Advocate

Hi @yuzeaa .

I have some problems with your code, and I'm hoping you might know how to fix them

When I open a file from vault for the first time (it wasn't previously on my local disk), and I try to Save As, the iProperties don't get changed. Do you have any idea on how to fix this?

 

Thanks.

0 Likes
Message 33 of 33

yuzeaa
Advocate
Advocate
Since I can't see the information on your computer, it's inconvenient for me to debug, and I haven't used Vault before. Maybe we can communicate some more detailed information via email (yuzeaa@163.com). However, I think this problem should be easy to solve.
0 Likes