Parameter with Python tuple
Tuple
The value of the PythonPart parameter can be created as a Python tuple object, defined by the used value types. A combination with a Python list is possible.
<Parameter>
<Name>TupleParameter</Name>
<Text>Tuple parameter</Text><!--(1)!-->
<Value>(10|Cube)</Value><!--(2)!-->
<ValueType>tuple(Double,String)</ValueType>
<MinValue>5,"?"</MinValue><!--(3)!-->
</Parameter>
- If an empty or only a single text is defined in the
<Text>
tag, all controls of the tuple values are created in one line in the property palette. -
The values must be separated by
|
character! This is also the case for<ValueTextId>
tag.Combination with a python list, ex. like this:
<Value>[(10|Cube)] * 5</Value>
is also possible. In this case the resulting controls would look like this: -
All optional tags can be used in the tuple parameter. An entry must be created for each value type, separated by a comma.
Named tuple
The value of the PythonPart parameter can be created as a Python namedtuple object, defined by the used value types. For each value type, an appropriate control will be created in the palette.
<Parameter>
<Name>UShape</Name>
<Text>,Diameter,Concrete cover,Top length,Bottom length</Text><!--(1)!-->
<Value>Param01.png|12|30|1000|2000</Value><!--(2)!-->
<ValueType>namedtuple(Picture,ReinfBarDiameter,ReinfConcreteCover,Length,Length)</ValueType>
<NamedTuple>
<TypeName>UShape</TypeName>
<FieldNames>Picture,Diameter,Cover,Length1,Length2</FieldNames>
</NamedTuple>
</Parameter>
-
Text for each control must be defined and separated with coma. If only one or no text is defined, all controls will be placed in one row like this:
-
The default values must be separated with
|
character.A combination with the Python list is possible. In this case the default values for each row must be separated by
;
List of named tuples
A parameter can be defined as a list of more than one namedtuple
<Parameter>
<Name>UShapeList</Name>
<Text>,Diameter,Concrete cover,Top length,Bottom length,"Group " + str($list_row + 1)|Edit</Text>
<Value>[Param01.png|12|30|1000|2000|0|;
Param02.png|12|30|1000|2000|0|;
Param03.png|12|30|1000|2000|0|]
</Value>
<EventId>0,0,0,0,0,1000<!--(1)!-->,0</EventId>
<ValueType>namedtuple(Picture,ReinfBarDiameter,ReinfConcreteCover,Length,Length,Button<!--(2)!-->,Separator)</ValueType>
<NamedTuple>
<TypeName>UShape</TypeName>
<FieldNames>Picture,Diameter,Cover,Length1,Length2,Button,Separator</FieldNames>
</NamedTuple>
<MinValue>,,,100,200,,</MinValue><!--(3)!-->
</Parameter>
-
One of the elements of the namedtuple is a Button, which must have an
<EventID>
defined. As the namedtuple consists of 7 elements, the<EventID>
must also be a list consisting of 7 integers, but only one of them is relevant. -
When a button is added to the group, the final event ID is a combination of the
<EventId>
and the row index. The extraction of these values is done with bitwise shifting of the event_id value as follows: -
All optional tags can be used in the tuple parameter. An entry must be created for each value type, separated by a comma.
Tip
See this chapter to learn how to show/hide or disable/enable a specific control of a namedtuple.
Controlling the palette text
Each row of the list can be provided with its own text in the property palette. This text is a part of the namedtuple and can be adressed in the script. To do this, the first field in the named tuple must be set to DisplayText and filled with the string for the row text. The value for the RowText field must be created in the xxx.py file. Here is an example:
stirrup_list = build_ele.StirrupList.value
for i in range(1, build_ele.ItemCount.value - 1):
stirrup_list[i] = stirrup_list[i]._replace(RowText = "Inside " + str(i))
stirrup_list[0] = stirrup_list[0]._replace(RowText = "Top")
if build_ele.ItemCount.value > 1:
stirrup_list[-1] = stirrup_list[-1]._replace(RowText = "Bottom")
The result may look like this: