Announcements
Attention for Customers without Multi-Factor Authentication or Single Sign-On - OTP Verification rolls out April 2025. Read all about it here.
j.romo
369 Views, 2 Replies

Create a User parameter using VB.net in a API

Hello Guys Im finally moving from Ilogic to VB.net and I have a problem that I cant find a sloution.

Im trying to use this code but keep getting the Null error. can you guys help me undertand the problem?

 Public Sub SampleCommandFunction2()
        Dim oPartDoc As PartDocument = ThisApplication
        Dim userParams As UserParameters = oPartDoc.ComponentDefinition.Parameters.UserParameters
        Dim newParam As UserParameter ' Placeholder
        Dim oFormat As CustomPropertyFormat
        Dim oParam As Parameters

        'LENGTH
        Try
            oParam = oPartDoc.ComponentDefinition.Parameters("LENGTH")
        Catch   'If the parameter was not found, then create a new one.
            newParam = userParams.AddByExpression("LENGTH", 0, "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
        End Try
End Sub