Change a User parameter type (Text) via VB.net Having issues

Change a User parameter type (Text) via VB.net Having issues

montylowe
Enthusiast Enthusiast
3,409 Views
7 Replies
Message 1 of 8

Change a User parameter type (Text) via VB.net Having issues

montylowe
Enthusiast
Enthusiast

Change a User parameter type (Text) via VB.net Having issues doing it thru the API can someone help

0 Likes
3,410 Views
7 Replies
Replies (7)
Message 2 of 8

YuhanZhang
Autodesk
Autodesk

Not quite sure the issue you encountered, can you share a snippet of code to reproduce it?



If this solves the problem please click ACCEPT SOLUTION so other people can find it easily.



Rocky Zhang
Inventor API PD
Manufacturing Solutions
Autodesk, Inc.

Message 3 of 8

Anonymous
Not applicable

I too am having problems setting a text parameter through the API. I'm trying to put the name, unit and value of key parameters into arrays and check other parts and assemblies for parameters with the same name and unit. If found, set the expression from the array. Here's where I make my arrays: 

For Each oCurrentParm In oParameters 

If oCurrentParm.IsKey = True Then

  arryParNames(intParCtr) = oCurrentParm.Name

  arryParValues(intParCtr) = oCurrentParm.Expression

  arryParUnits(intParCtr) = oCurrentParm.Units

  intParCtr = intParCtr + 1 

End If 

Next

Here's when I attempt to set the expressions:

If oCurrentParm.Name = arryParNames(intParCtr) And _

   oCurrentParm.Units = arryParUnits(intParCtr) Then

   oCurrentParm.Expression = arryParValues(intParCtr)

End If

It works for numeric parameters but not on text parameters. I thought sting quotes were the problem but I'm not sure. I did have double quotes and was trying to stip a pair off but still no luck. Then, I saw another post where they we adding quotes to some multivalue parameters and wondered if I needed same. (more quotes instead of less)

Thanks,

Rosco

Inventor 2011

WIndow 7

0 Likes
Message 4 of 8

YuhanZhang
Autodesk
Autodesk

The Parameter.Value can be set for text parameter .

 

Sub TextParamTest()
    Dim oDoc As PartDocument
    Set oDoc = ThisApplication.Documents.Add(kPartDocumentObject)
    
    Dim oParam As UserParameter
    Set oParam = oDoc.ComponentDefinition.Parameters.UserParameters.AddByValue("TextParam", "Test", "TEXT")
    
    Debug.Print oParam.Value
    Debug.Print oParam.Expression
    oParam.Value = "Change test"
     
    Debug.Print oParam.Value
    Debug.Print oParam.Expression
End Sub

 I will file the issue for set with Expression.

 

 

 



If this solves the problem please click ACCEPT SOLUTION so other people can find it easily.



Rocky Zhang
Inventor API PD
Manufacturing Solutions
Autodesk, Inc.

Message 5 of 8

Anonymous
Not applicable

Thank you very much, I now check the parameter units before setting its value. If its "Text", I use oCurrentParm.value and if its not I use OCurrentParm.Expression. It seems to be working well. I tag a parameter as "Key" in an assembly, run the program, and all parameters with matching names in children of the assembly are set to the key parameter's value. However, I get the parameters in each component definition of each component occurance in component occurances for checking against my list of key parameters.  This is causing repetitive updating of part/assemblies with more than one occurance. No big deal, it works, but I'd like to just update an occurance one time. Thanks for any ideas.

Rosco

Inventor 2011

Windows 7    

Message 6 of 8

Anonymous
Not applicable

Thanks for this. 

 

I was running into a problem that has been annoying me all day. I was setting an integer value using parameter.value instead of parameter.expression and couldn't figure out why. This explains it!

 

Wish the OP marked this post as solved and the API Docs were a bit more clear on this. The Parameter.Value property description reads:

 

Gets/(Sets) the value of this parameter. Numeric values are in database units. Setting this is equivalent to setting the 'Expression' with a constant string. 'Set' may not be allowed on some parameter types.

 

Which didn't really make it obvious to me that the parameter.value property was causing all my pain. 

0 Likes
Message 7 of 8

tonythm
Advocate
Advocate

Hi @montylowe 

 

Public Sub CreateTextBooleanUserParameter()
    Dim oDoc As PartDocument
    Set oDoc = ThisApplication.Documents.Add(kPartDocumentObject)
    
    Dim oUserParameters As UserParameters
    Set oUserParameters = oDoc.ComponentDefinition.Parameters.UserParameters
    
    Dim oTextParam As UserParameter
    Set oTextParam = oUserParameters.AddByValue("Printer_Name", "Inventor_3D_Printer1", kTextUnits)
    
    Dim oBooleanParam As UserParameter
    Set oBooleanParam = oUserParameters.AddByValue("Auto_Print", True, kBooleanUnits)
End Sub
0 Likes
Message 8 of 8

WCrihfield
Mentor
Mentor

@tonythm, @montylowe , @Anonymous , @Anonymous 

So, just to sum this all up, and finally close the topic for future readers who find this by searching...

When working with Parameter, ModelParameters, UserParameters, etc., by code, the following guidelines are in effect:

 

To create new Text type parameters or new Boolean (Yes/No, True/False) type parameters, you need to create it using the 'Value' property of the parameter, and not by using its 'Expression' property.

 

To create new Numerical type parameters you can use either its 'Value' property or its 'Expression' property.

When creating new Numerical type parameters, if you use the 'Value' property, the result will be a simple numerical value, not an equation.

When creating new Numerical type parameters, if you use the 'Expression' property, you can specify an equation, which can include the names of other parameters, and that equation will be maintained within the parameter, or you can simply specify a simple numerical value instead of an equation, and it will also work.

Using the 'Expression' property of a numerical parameter, is the only way to maintain an equation within the parameter, instead of just a simple numerical value.  Using the 'Value' property of a numerical parameter can only result in a simple numerical value, and can not store an equation.

 

If...Then statements and other non-mathematical logical code can not be entered into the expression of a parameter, because they are not purely numerical.

 

Any questions?

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes