Add a prefix to a parameter

Add a prefix to a parameter

asmenut
Enthusiast Enthusiast
398 Views
2 Replies
Message 1 of 3

Add a prefix to a parameter

asmenut
Enthusiast
Enthusiast

Is there a way (ilogic or VBA) to loop through user parameters and rename each with a prefix (see example)

 

"Belt_Width" >> "RD722_Belt_Width"

 

Thank you in advance

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

asmenut
Enthusiast
Enthusiast

Let's re-write this to make it more understandable:

 

I have a number of parameters (over 100) that I import to my designs.  In this particular design, I have multiple variations of the same design being created in the same multi body solid.  I need to be able to differentiate between the design parameters so it will be easier to debug and modify if required.  What I am trying to do is to loop through a set of parameters (imported from xml) and give a prefix to them (i.e. try/catch to ensure previous prefixes aren't renamed).

0 Likes
Message 3 of 3

asmenut
Enthusiast
Enthusiast
Accepted solution

I fingered it out.  Thanks for the views.  The following code will ask for a prefix string then loop through the existing user parameters and rename them.  I will work on the if existed at a later time

 

Dim i As Integer
Dim oTempString As String 
Dim oDoc As PartDocument = ThisDoc.Document
Dim InputPrefix As String
Dim myparam As String
Dim NewName As String

If oDoc.DocumentType = kPartDocumentObject Then
	Dim oPartCompDef As PartComponentDefinition = oDoc.ComponentDefinition
	myparam = InputBox("Enter Prefix", "Prefix", InputPrefix)
	Try
		For i = 1 To oPartCompDef.Parameters.UserParameters.Count
			oTempString = oPartCompDef.Parameters.UserParameters(i).Name
				
			NewName =myparam & "-" & oTempString
			oPartCompDef.Parameters.UserParameters(i).Name = NewName
			MsgBox(NewName)
		Next i
	Catch
		MsgBox("Parameter " & oPartCompDef.Parameters.UserParameters(i).Name & " could not be renamed to " & myparam & oTempString &  vbCrLf & "Please check results.", MsgBoxStyle.Critical,"Rename User Parameters")
	End Try
	
End If
0 Likes