Hello I want to add some user parameters but if the parameter exists skip the creation of such parameters
My code is like this
Private Sub Button_Click(sender As Object, e As RoutedEventArgs)
Dim userParams As UserParameters = oPartDoc.ComponentDefinition.Parameters.UserParameters
Dim newParam As UserParameter ' Placeholder
Dim oFormat As CustomPropertyFormat
Dim oParam As Parameters
Dim oCantidad As String = cantidadTXTBox.Text
If oCantidad Is Nothing Then
MsgBox("Poner numero de piezas en textbox")
Exit Sub
End If
'LENGTH
Try
oParam = oPartDoc.ComponentDefinition.Parameters.UserParameters("Cantidad")
Catch 'If the parameter was not found, then create a new one.
newParam = userParams.AddByExpression("Cantidad", oCantidad, "mm") ' Create the Parameter as per above
newParam.ExposedAsProperty = True 'Flag for Export
oFormat = newParam.CustomPropertyFormat 'For some reason or other this line is needed to enable the following formatting
oFormat.PropertyType = Inventor.CustomPropertyTypeEnum.kTextPropertyType
oFormat.Precision = Inventor.CustomPropertyPrecisionEnum.kZeroDecimalPlacePrecision 'Set one decimal place
'oFormat.Units="mm" 'Units
oFormat.ShowUnitsString = False
oFormat.ShowLeadingZeros = False
oFormat.ShowTrailingZeros = False
MsgBox("Cantidad agregada")
End Try
End Sub
but it creates the parameter if it doesent exist but if it exists it creates a nother one the try catch is not working.
"By the way is there another way to create parameters easier?.
thanks in advance
Solved! Go to Solution.
Solved by A.Acheson. Go to Solution.
Hi @j.romoYDW7Q
Your issue begins in the Try statement. oParam is declared as parameters collection so more than 1. Then in the try statement you set oParam as a single parameter. Silly Example userParams is the dozen eggs where as userParam is the egg.
Also you can be more precise and declare oParam as a userParameter
Incorrect
Dim oParam As Parameters
Try
oParam = oPartDoc.ComponentDefinition.Parameters.UserParameters("Cantidad")
Catch
newParam = userParams.AddByExpression("Cantidad", oCantidad, "mm") ' Create the Parameter as per above
End Try
Correct
Dim userParams As UserParameters = oPartDoc.ComponentDefinition.Parameters.UserParameters
Dim userParam As UserParameter ' Placeholder
Dim oCantidad As String = cantidadTXTBox.Text
Try
userParam = userParams.Item ("Cantidad")
Catch 'If the parameter was not found, then create a new one.
userParam = userParams.AddByExpression("Cantidad", oCantidad, "mm") ' Create the
End Try
Can't find what you're looking for? Ask the community or share your knowledge.