Announcements
Attention for Customers without Multi-Factor Authentication or Single Sign-On - OTP Verification rolls out April 2025. Read all about it here.
J-Camper
in reply to: Anonymous

I put together a little sample of how you can add different types of User Parameters:

'Access User parameters of the active document
Dim oMyParameters As UserParameters = ThisApplication.ActiveDocument.ComponentDefinition.Parameters.UserParameters 
'Create list of Parameter names of type: number
Dim numParams As New List(Of String) 
numParams.AddRange({"Height", "Length", "Thickness"})
'Create list of Parameter names of type: text
Dim textParams As New List(Of String) 
textParams.AddRange({"Name", "Side", "Orientation"})
'Create list of Parameter names of type: True/False
Dim booleanParams As New List(Of String) 
booleanParams.AddRange({"Two_Side_Machining", "Buyout"})
'Testing and Creation of User Parameters of type: number
For Each item In numParams
	Try 'Check if User Parameter exists
		Param = oMyParameters.Item(item)
	Catch 'Parameter doesn't exist as a User Parameter
		Try 'attempt to create new parameter
			oMyParameters.AddByExpression(item, 0, UnitsTypeEnum.kInchLengthUnits) '(Name, Value, Unit Type)
		Catch 'Parameter exists but not as a User Parameter
			MessageBox.Show("The Parameter: " & item & " exists as a parameter, but is not a user parameter.", "Creation Failure")
		End Try
	End Try
Next
'Testing and Creation of User Parameters of type: text
For Each item In textParams
	Try 'Check if User Parameter exists
		Param = oMyParameters.Item(item)
	Catch 'Parameter doesn't exist as a User Parameter
		Try 'attempt to create new parameter
			oMyParameters.AddByValue(item, "filler", UnitsTypeEnum.kTextUnits) '(Name, Value, Unit Type)
		Catch 'Parameter exists but not as a User Parameter
			MessageBox.Show("The Parameter: " & item & " exists as a parameter, but is not a user parameter.", "Creation Failure")
		End Try
	End Try
Next
'Testing and Creation of User Parameters of type: True/False
For Each item In booleanParams
	Try 'Check if User Parameter exists
		Param = oMyParameters.Item(item)
	Catch 'Parameter doesn't exist as a User Parameter
		Try 'attempt to create new parameter
			oMyParameters.AddByValue(item, True, UnitsTypeEnum.kBooleanUnits) '(Name, Value, Unit Type)
		Catch 'Parameter exists but not as a User Parameter
			MessageBox.Show("The Parameter: " & item & " exists as a parameter, but is not a user parameter.", "Creation Failure")
		End Try
	End Try
Next

 I tried to add enough comments to help you understand what is happening so you can modify as needed.  Let me know if you have any questions.