Setlist bug?

Setlist bug?

richard_griffin
Enthusiast Enthusiast
384 Views
2 Replies
Message 1 of 3

Setlist bug?

richard_griffin
Enthusiast
Enthusiast

I have the following basic code-

MultiValue.SetValueOptions(True, DefaultIndex := 0)

If Colour = "Red" Then

	MultiValue.SetList("Thickness", 0.55, 0.75, 1.0, 1.25)

ElseIf Colour = "Blue" Then

	MultiValue.SetList("Thickness", 2, 3, 4, 5)

		
ElseIf Colour = "Green" Then

	MultiValue.SetList("Thickness", 0.1, 0.2, 0.3, 0.4, 0.5)

End If

 Red and blue work as intended, when i pick blue, the multivalue picks the first option, same for red.

 

However, when I select green, it picks the last option. Have i misinterpreted the line "MultiValue.SetValueOptions(True, DefaultIndex := 0)" or is it not doing what its supposed to when it comes to green?

0 Likes
385 Views
2 Replies
Replies (2)
Message 2 of 3

WCrihfield
Mentor
Mentor

It can sometimes seem as though the Integer you specify for the default index to use within that line doesn't have any effect.  I believe this is a situational issue though.

If the target parameter already exists, and it is numerical, it has to already have a value.  Or if it is a Text type parameter, it can seem to have no value, but that isn't actually correct, because it must, so it is simply a blank (or Null) string.

If the target parameter already exists and already has a current value, then it won't matter how you have that index number set, it is going to choose the value that is either, the closest numerical match to the existing value, or the closes alphabetical match to the existing value, as the new active value of the parameter, regardless of how you set the default Index.  And in the case of an text type parameter, if the parameter had a Null string in it before you set the list to it, it will always use the value from the provided list that is nearest the front of the alphabet.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

Message 3 of 3

WCrihfield
Mentor
Mentor

There is another way to create (or update the values of) a multi-value parameter, that may work better for you.

Here is a simple code that creates a new user parameter (in either a part or an assembly file), assigns it a useless value, within the creation line, then immediately afterwards uses the parameters "ExpressionList" Property, and its "SetExpressionList" sub, to set a whole new set of values to the parameter.  Within that SetExpressionList sub, there are optional options.  The first one after the input list, is a boolean asking if you want to replace the existing value, which in this case we are saying True to.  Then it asks for the index of the value from the input list we want to assign as the active value.  As you know, the index is zero-based (first item is item zero, instead of item one), so when I specify index 2, it will use the third value from the input list as the active value.

Dim oUParams As UserParameters = ThisDoc.Document.ComponentDefinition.Parameters.UserParameters
Dim oUParam As UserParameter = oUParams.AddByValue("NewParam", 25, UnitsTypeEnum.kInchLengthUnits)
Dim oExpressions() As String = {2,4,6,8,10}
oUParam.ExpressionList.se.SetExpressionList(oExpressions,True,2)

You can also set the ExpressionList of a pre-existing parameter with similar code to the last two lines.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes