Creating a "dynamic" user parameter
I am trying to create a script that turns the part number into a user parameter. The reason is that I want to use the part number in a text field on an .idw. Creating a parameter allows me to do this. Since I do not want endless amounts of these parameters I thought about deleting the parameter if it exists and then create it again.
So far I came up with the following code:
Dim PartNumber As Parameter
'Define parameter in the current user parameters of the current document
Param = ThisApplication.ActiveDocument.ComponentDefinition.Parameters
UserParam = Param.UserParameters
For Each UserParam In Param
'Check if the parameter PartNumber exists
If UserParam.Name = "PartNumber"
'Delete the parameter if it does exist
Parameter.Param("PartNumber").Delete
End If
Next
'Create the parameter
PartNumber = UserParam.AddByValue("PartNumber", iProperties.Value("Project", "Part Number"), UnitsTypeEnum.kTextUnits)
'Set a comment
Parameter.Param("PartNumber").Comment = "Set by a rule, do not alter"
'Update file
iLogicVb.UpdateWhenDone = True
The codes work seperately (meaning the for loop deleting the parameter if it exists works and the creation of the parameter itself works) but together they do not. The error message I get is: "The public member AddByValue for type UserParameter was not found."
What am I doing wrong?
Link copied