How to create a new file name adding suffix in a new folder?

How to create a new file name adding suffix in a new folder?

ikilic1461
Enthusiast Enthusiast
3,697 Views
13 Replies
Message 1 of 14

How to create a new file name adding suffix in a new folder?

ikilic1461
Enthusiast
Enthusiast

Hello ;

I have a ilogic parametric assembly here and I want to add a prefix to all items ,including sub assemblies ,parts in product tree and save as to a new folder(like pack and go )

For example ; firts item's name "Oil Entry DOF Tube" , after apply my desired rules I want to add project name as prefix. 

I will put a button and write "Enter project name "

Project name : PA366

Then it will become "PA366_Oil Entry DOF Tube"

 

File_name.PNG

 

0 Likes
3,698 Views
13 Replies
Replies (13)
Message 2 of 14

bradeneuropeArthur
Mentor
Mentor

You could use ilogic copy design, found in the ribbon zero documents!

Regards,

Arthur Knoors

Autodesk Affiliations & Links:
blue LinkedIn LogoSquare Youtube Logo Isolated on White Background


Autodesk Software:Inventor Professional 2025 | Vault Professional 2024 | Autocad Mechanical 2024
Programming Skills:Vba | Vb.net (Add ins Vault / Inventor, Applications) | I-logic
Programming Examples:
Drawing List!|
Toggle Drawing Sheet!|
Workplane Resize!|
Drawing View Locker!|
Multi Sheet to Mono Sheet!|
Drawing Weld Symbols!|
Drawing View Label Align!|
Open From Balloon!|
Model State Lock!
Posts and Ideas:
My Ideas|
Dimension Component!|
Partlist Export!|
Derive I-properties!|
Vault Prompts Via API!|
Vault Handbook/Manual!|
Drawing Toggle Sheets!|
Vault Defer Update!

! For administrative reasons, please mark a "Solution as solved" when the issue is solved !


 


EESignature

0 Likes
Message 3 of 14

ikilic1461
Enthusiast
Enthusiast

ıs there another solution to be able to add to the form with rule? 

Because I have some form paremeters , I also want to include project number too , then want to change all item's file name with this prefix. 

Capture.PNG

Thanks .

 

0 Likes
Message 4 of 14

ikilic1461
Enthusiast
Enthusiast

Hello @bradeneuropeArthur ;

I have some parameters from the parts in the assembly , when I use ilogic copy design , in the copied assembly the parameter names stay as previous one , so the rule gives error. 

You can see below screenshoot, in model tree it is with prefix name which created with ilogic design copy but in the rule they remain as previous one. 

If you help me I would be grateful 

 

Capture.PNG

 

0 Likes
Message 5 of 14

WCrihfield
Mentor
Mentor

Hi @ikilic1461.  Besides what I mentioned on your other current forum topic, below is another possible workaround way to 'fix' the rule afterwards, if needed, but this one can be pretty tricky to implement correctly.  This would be something you would need to run after the design copy process has completed, to help fix the contents of the iLogic rule to reflect the new component names.  

 

It is not 'perfect', but may work OK if working from a Template type situation (copying a template assembly files to new files).  This is because it is expecting the names of the components in the rule to not already have a 'prefix' in their names.  If they do already have a prefix in their names, such as when copying one 'copied' assembly to make another, then the 'find & replace' task will not be working with the correct 'find' text.  If that is the case, then you may need to redefine how the 'find' text is dictated by replacing old/previous prefix with new/current prefix, instead of just removing prefix.

Sub Main
	Dim oADoc As AssemblyDocument = TryCast(ThisDoc.Document, Inventor.AssemblyDocument)
	If oADoc Is Nothing Then Logger.Debug(iLogicVb.RuleName & " exited (Wrong DocumentType)") : Return
	Dim oOccs As ComponentOccurrences = oADoc.ComponentDefinition.Occurrences
	If oOccs.Count = 0 Then Return
	Dim sPrefix As String = InputBox("Enter Prefix Text.", "Prefix", "")
	If sPrefix = "" Then Return
	'<<< a Dictionary to hold each 'old/previous' and 'new/current' component BrowserNode name, in pairs, in a list >>>
	'<<< each 'entry' has a 'Key' and a 'Value' (Key = old or previous name, Value = new or current name) >>>
	Dim oDict As New Dictionary(Of String, String)
	'<<< a transaction bundles multiple actions into one item in the UNDO list >>>
	Dim oTrans As Inventor.Transaction
	oTrans = ThisApplication.TransactionManager.StartTransaction(oADoc, "Update iLogic Rule Component Names")
	For Each oOcc As ComponentOccurrence In oOccs
		'<<< get name of component BrowserNode without the 'Prefix' >>>
		Dim sOccNameWithoutPrefix As String = oOcc.Name.Replace(sPrefix, "")
		'<<< if sOccNameWithoutPrefix is not already in dictionary, then add it, along with current name >>>
		If Not oDict.ContainsKey(sOccNameWithoutPrefix) Then
			oDict.Add(sOccNameWithoutPrefix, oOcc.Name)
		End If
	Next 'oOcc
	If oDict.Count = 0 Then : oTrans.Abort : Return : End If
	'<<< run the custom Sub routine below with following line of code >>>
	'<<< IMPORTANT:  EDIT RULE NAME IN NEXT LINE >>>
	FindReplaceTextInRule(oADoc, "RuleName", oDict)
	oTrans.End
End Sub

Sub FindReplaceTextInRule(oDoc As Inventor.Document, sRuleName As String, _
oOldAndNewPairs As Dictionary(Of String, String))
	If oDoc Is Nothing OrElse oDoc.IsModifiable = False Then Return
	If sRuleName = "" Then Return
	If oOldAndNewPairs Is Nothing OrElse oOldAndNewPairs.Count = 0 Then Return
	Dim oRule As iLogicRule = iLogicVb.Automation.GetRule(oDoc, sRuleName)
	If oRule Is Nothing Then
		Logger.Debug("iLogic Rule named '" & sRuleName & "' not found!")
		Return
	End If
	Dim sRuleText As String = oRule.Text
	If sRuleText = "" Then Return
	For Each oEntry As KeyValuePair(Of String, String) In oOldAndNewPairs
		Try
			sRuleText = sRuleText.Replace(oEntry.Key, oEntry.Value)
		Catch
			Logger.Error("Error editing iLogic Rule named " & sRuleName & vbCrLf & _
			"while replacing:  " & oEntry.Key & vbCrLf & _
			"with:  " & oEntry.Value)
		End Try
	Next 'oEntry
	oRule.Text = sRuleText
End Sub

I also have an alternative custom Sub routine with the same name, but which requests a single 'text to find' and 'text to replace the with', instead of a Dictionary(Of String, String), for when you only need to replace one term in a rule.

Sub FindReplaceTextInRule(oDoc As Inventor.Document, sRuleName As String, _
sTextToFind As String, sReplacementText As String)
	If oDoc Is Nothing OrElse oDoc.IsModifiable = False Then Return
	If sRuleName = "" OrElse sTextToFind = "" Then Return
	Dim oRule As iLogicRule = iLogicVb.Automation.GetRule(oDoc, sRuleName)
	If oRule Is Nothing Then
		Logger.Debug("iLogic Rule named '" & sRuleName & "' not found!")
		Return
	End If
	Dim sRuleText As String = oRule.Text
	If sRuleText = "" Then Return
	Try
		sRuleText = sRuleText.Replace(sTextToFind, sReplacementText)
	Catch
		Logger.Error("Error editing iLogic Rule named " & sRuleName & vbCrLf & _
		"while trying to replace:  " & sTextToFind & vbCrLf & _
		"with the following:  " & sReplacementText)
	End Try
	oRule.Text = sRuleText
End Sub

If this solved your problem, or answered your question, please click ACCEPT SOLUTION .
Or, if this helped you, please click (LIKE or KUDOS) 👍.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

Message 6 of 14

bradeneuropeArthur
Mentor
Mentor

You should use a static occurrence name which stays always the same...

Regards,

Arthur Knoors

Autodesk Affiliations & Links:
blue LinkedIn LogoSquare Youtube Logo Isolated on White Background


Autodesk Software:Inventor Professional 2025 | Vault Professional 2024 | Autocad Mechanical 2024
Programming Skills:Vba | Vb.net (Add ins Vault / Inventor, Applications) | I-logic
Programming Examples:
Drawing List!|
Toggle Drawing Sheet!|
Workplane Resize!|
Drawing View Locker!|
Multi Sheet to Mono Sheet!|
Drawing Weld Symbols!|
Drawing View Label Align!|
Open From Balloon!|
Model State Lock!
Posts and Ideas:
My Ideas|
Dimension Component!|
Partlist Export!|
Derive I-properties!|
Vault Prompts Via API!|
Vault Handbook/Manual!|
Drawing Toggle Sheets!|
Vault Defer Update!

! For administrative reasons, please mark a "Solution as solved" when the issue is solved !


 


EESignature

Message 7 of 14

ikilic1461
Enthusiast
Enthusiast

Hello @WCrihfield ;

I am so grateful for your endless support, But , I see I couldn't solve my problem yet. 

I also attached  my study here. If you have time you may integrate your statements .

Many thanks 

0 Likes
Message 8 of 14

ikilic1461
Enthusiast
Enthusiast

Hello @bradeneuropeArthur ;

My study attached in the previous message.

I couldn't understand how to do it . If you have time and solve this issue I would be grateful.

Many thanks. 

0 Likes
Message 9 of 14

bradeneuropeArthur
Mentor
Mentor
I will support you. Will come back to you, ok?

Regards,

Arthur Knoors

Autodesk Affiliations & Links:
blue LinkedIn LogoSquare Youtube Logo Isolated on White Background


Autodesk Software:Inventor Professional 2025 | Vault Professional 2024 | Autocad Mechanical 2024
Programming Skills:Vba | Vb.net (Add ins Vault / Inventor, Applications) | I-logic
Programming Examples:
Drawing List!|
Toggle Drawing Sheet!|
Workplane Resize!|
Drawing View Locker!|
Multi Sheet to Mono Sheet!|
Drawing Weld Symbols!|
Drawing View Label Align!|
Open From Balloon!|
Model State Lock!
Posts and Ideas:
My Ideas|
Dimension Component!|
Partlist Export!|
Derive I-properties!|
Vault Prompts Via API!|
Vault Handbook/Manual!|
Drawing Toggle Sheets!|
Vault Defer Update!

! For administrative reasons, please mark a "Solution as solved" when the issue is solved !


 


EESignature

Message 10 of 14

ikilic1461
Enthusiast
Enthusiast

Hello @bradeneuropeArthur ;

Thank you , I will be waiting for it. 

0 Likes
Message 11 of 14

bradeneuropeArthur
Mentor
Mentor

Hi,

 

First create a  Custom Property in each part in the assembly Called "MyDisplayName" and give this the values as per picture.

bradeneuropeArthur_0-1708635924368.png

Than use this i-locig code to set each time you copy the value back to the default (Displayname)

Dim a As AssemblyDocument = ThisAssembly.Document
Dim ac As AssemblyComponentDefinition = a.ComponentDefinition
Dim ao As ComponentOccurrence 

For Each ao In ac.Occurrences
	Dim d As Document = ao.Definition.Document
	Dim dps As PropertySet = d.PropertySets.Item(4)
	Dim dp As [Property] = dps.Item("MyDisplayName")
	ao.Name = dp.Value
	Next

 

Now the problem from the rename is away since the displayname is always static or overwitable with the "MyDisplayName" value of each occurence in this assembly.

Regards,

Arthur Knoors

Autodesk Affiliations & Links:
blue LinkedIn LogoSquare Youtube Logo Isolated on White Background


Autodesk Software:Inventor Professional 2025 | Vault Professional 2024 | Autocad Mechanical 2024
Programming Skills:Vba | Vb.net (Add ins Vault / Inventor, Applications) | I-logic
Programming Examples:
Drawing List!|
Toggle Drawing Sheet!|
Workplane Resize!|
Drawing View Locker!|
Multi Sheet to Mono Sheet!|
Drawing Weld Symbols!|
Drawing View Label Align!|
Open From Balloon!|
Model State Lock!
Posts and Ideas:
My Ideas|
Dimension Component!|
Partlist Export!|
Derive I-properties!|
Vault Prompts Via API!|
Vault Handbook/Manual!|
Drawing Toggle Sheets!|
Vault Defer Update!

! For administrative reasons, please mark a "Solution as solved" when the issue is solved !


 


EESignature

0 Likes
Message 12 of 14

ikilic1461
Enthusiast
Enthusiast

Hello @bradeneuropeArthur  ;

I created a custom property in 7 parts which I got parameters in my assembly  as you mentioned "MyDisplayName".

But at the end I got this error . Then form didn't work. 

I am also attaching model here. 

Capture.PNG

 

MyDisplayName = Oil Entry DOF Tube.ipt:1

MyDisplayName = Interval DOF Tube.ipt:1

MyDisplayName = End DOF Tube.ipt:1

MyDisplayName = DOF Oil Entry End Flange.ipt:1

MyDisplayName = End Stop Board Packing Block.ipt:1

MyDisplayName = DOF Tube Support Board.ipt:1

MyDisplayName = Petal Washer Seal.ipt:1

 

Capture.PNG

0 Likes
Message 13 of 14

bradeneuropeArthur
Mentor
Mentor

I have got it working for you.

What you forgot is to add "MyDisplayName" to each compontent even it is an empty string.

Also changed this in the code:

For Each ao In ac.Occurrences
	Dim d As Document = ao.Definition.Document
	Dim dps As PropertySet = d.PropertySets.Item(4)
	Try
		Dim dp As [Property] = dps.Item("MyDisplayName")
	ao.Name = dp.Value
		Catch
			
		End Try
	
	Next

See the movie for explanation too

 

 

Regards,

Arthur Knoors

Autodesk Affiliations & Links:
blue LinkedIn LogoSquare Youtube Logo Isolated on White Background


Autodesk Software:Inventor Professional 2025 | Vault Professional 2024 | Autocad Mechanical 2024
Programming Skills:Vba | Vb.net (Add ins Vault / Inventor, Applications) | I-logic
Programming Examples:
Drawing List!|
Toggle Drawing Sheet!|
Workplane Resize!|
Drawing View Locker!|
Multi Sheet to Mono Sheet!|
Drawing Weld Symbols!|
Drawing View Label Align!|
Open From Balloon!|
Model State Lock!
Posts and Ideas:
My Ideas|
Dimension Component!|
Partlist Export!|
Derive I-properties!|
Vault Prompts Via API!|
Vault Handbook/Manual!|
Drawing Toggle Sheets!|
Vault Defer Update!

! For administrative reasons, please mark a "Solution as solved" when the issue is solved !


 


EESignature

Message 14 of 14

ikilic1461
Enthusiast
Enthusiast

Hello @bradeneuropeArthur ;

Even  if I applied to the all items I got en error again ;

There is something wrong or missing.

If possible , can you share your modifed file?

 

Capture.PNG

0 Likes