Rename part of text string

Rename part of text string

madstrolle
Enthusiast Enthusiast
898 Views
7 Replies
Message 1 of 8

Rename part of text string

madstrolle
Enthusiast
Enthusiast

Hi,

I use Pack and go to copy a project and afterwards I use Design assistant to rename the files. Eg. as shown on the picture the files are named 41826_W01 and then i rename it 42485_W01, so it's only the first 5 characters that i'm renaming. When it's huge projects it takes ages to rename all the files in Design assistant.

There must be a quicker and easier way?

 

Thanks in advance 🙂

 

madstrolle_0-1689188439257.png

 

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

JelteDeJong
Mentor
Mentor

It's possible to create a copy design function but it's not as easy as it might think. Therefore I wonder if you ever have looked at the copy design function of the Vault. In the basic Vault that you get for free with Inventor you can do a search and replace in the file names.

https://help.autodesk.com/view/VAULT/2023/ENU/?guid=GUID-EC6894D4-36E4-48B9-84D6-1F9B41240A0B

And if you have a look at Workgroup and Professional vault then you have even better options.

https://help.autodesk.com/view/VAULT/2023/ENU/?guid=GUID-9865E786-4FE2-40AC-B951-1FEBA910ECCC

 

Jelte de Jong
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.

EESignature


Blog: hjalte.nl - github.com

Message 3 of 8

Martin-Winkler-Consulting
Advisor
Advisor

Do you rename the files, or are there only the "wrong" names in the browser tree?

Martin Winkler
CAD Developer
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.


EESignature

0 Likes
Message 4 of 8

madstrolle
Enthusiast
Enthusiast

I'm renaming the files.

0 Likes
Message 5 of 8

madstrolle
Enthusiast
Enthusiast

@JelteDeJong thank you for your suggestion, but unfortunately we don't use Vault.

0 Likes
Message 6 of 8

Curtis_Waguespack
Consultant
Consultant

Hi @madstrolle 

 

Here is a basic example.

 

I hope this helps.
Best of luck to you in all of your Inventor pursuits,
Curtis
http://inventortrenches.blogspot.com

 

Where the setup is something like this:

Curtis_Waguespack_0-1689258965892.png

 

Curtis_Waguespack_1-1689258991699.png

 

Resulting in this:

 

Curtis_Waguespack_2-1689259011456.png

 

Curtis_Waguespack_3-1689259059321.png

 

 

 

'This rule expects the following:
'	an original Path such As: "C:\Temp\Projects\41826\41826_123456.iam"
'	a parameter called current_ProjectNumber
'	a parameter called new_ProjectNumber, with a value such as 55555
'
'the result would be a new path such as: "C:\Temp\Projects\55555\55555_123456.iam"

Sub Main
	Dim oDoc As AssemblyDocument
	oDoc = ThisDoc.Document
	oNewname = UpdateName(oDoc)
	
	If oDoc.ComponentDefinition.Occurrences.Count > 0 Then
		Call TraverseAssembly(oDoc.ComponentDefinition.Occurrences, oNewname)
	End If

	If Not oNewname = oDoc.FullFileName Then
		oDoc.SaveAs(oNewname, False)
	End If
	
	InventorVb.DocumentUpdate()

End Sub

Sub TraverseAssembly(Occurrences As ComponentOccurrences, oNewname As String)
	On Error Resume Next
	Dim oOcc As ComponentOccurrence
	Dim oDoc As Document
	For Each oOcc In Occurrences
		If oOcc.DefinitionDocumentType = kAssemblyDocumentObject Then
			Call TraverseAssembly(oOcc.SubOccurrences, oNewname)
		End If

		oDoc = oOcc.Definition.Document
		oNewname = UpdateName(oDoc)

		oDoc.SaveAs(oNewname, False)
		oDoc.PropertySets("Design Tracking Properties")("Part Number").Value = IO.Path.GetFileName(oDoc.fullfilename)
		
	Next
End Sub

Function UpdateName(oDoc As Document)

	Dim sName As String = oDoc.FullFileName
	Dim sPath As String = IO.Path.GetDirectoryName(sName)
	Dim sSplitArray = Split(sPath,"\")
	Dim sCurPN As String = sSplitArray(sSplitArray.Length - 1)	
	Dim sNewPN As String = Trim(Parameter("new_ProjectNumber"))
	Parameter("current_ProjectNumber") = sNewPN

	Dim oNewname As String = Replace(sName, sCurPN, sNewPN)

	sFolderPath = IO.Path.GetDirectoryName(oNewname)

	If Not System.IO.Directory.Exists(sFolderPath) Then
		System.IO.Directory.CreateDirectory(sFolderPath)
	End If

	Return oNewname

End Function

 

EESignature

0 Likes
Message 7 of 8

madstrolle
Enthusiast
Enthusiast

@Curtis_Waguespack 

Thank you very much for taking your time to help me.

Unfortunately it is not working. 

This is our drives that contain our files:

madstrolle_0-1689261200810.png

And then our files a named according the drives. Eg. 41826_C01, 41826_C02, 41826_W01 etc.

 

 

 

0 Likes
Message 8 of 8

Curtis_Waguespack
Consultant
Consultant
Accepted solution

@madstrolle wrote:

 

Thank you very much for taking your time to help me.

Unfortunately it is not working. 

This is our drives that contain our files:


It works as written for the file and folder structure examples I provided.

 

Unfortunately, the nature of this type of copy design code is that it unique to each organization, often with a lot of exceptions as well, and so it would be too time consuming for me to tailor it to your needs for you.

 

I would suggest setting up some simple example files that follow the structure I showed in the example, and then use that to modify this example to your specifics. 

EESignature