Edit control
Defining a parameter with an edit control means allowing the user of the PythonPart to freely type in the desired value of a parameter in an input field.
Value types
String
A parameter containing a string of characters or, in other words, a single line of unformatted text.
<Parameter>
<Name>String</Name>
<Text>String parameter</Text>
<Value>This is a string</Value>
<ValueType>String</ValueType>
</Parameter>
Integer
A parameter containing an integer number.
<Parameter>
<Name>Integer</Name>
<Text>Integer</Text>
<Value>123</Value>
<ValueType>Integer</ValueType>
</Parameter>
Double
A parameter containing a floating-point value.
<Parameter>
<Name>Double</Name>
<Text>Floating-point</Text>
<Value>47.11</Value>
<ValueType>Double</ValueType>
</Parameter>
Length
A parameter containing length. In the palette the value is displayed in the current ALLPLAN length unit. In the script and in the .pyp file however, the value would always be given in mm.
<Parameter>
<Name>Length</Name>
<Text>Length</Text>
<Value>4711</Value> <!--(1)!-->
<ValueType>Length</ValueType>
</Parameter>
-
An additional default value for an imperial unit can be set with the tag
<ImperialValue>
like:
Area
A parameter containing area. In the palette the value is displayed in the current ALLPLAN length unit (squared). In the script and in the .pyp file however, the value would always be given in mm².
<Parameter>
<Name>Area</Name>
<Text>Area</Text>
<Value>133161126</Value>
<ValueType>Area</ValueType>
</Parameter>
Volume
A parameter containing volume. In the palette the value is displayed in the current ALLPLAN length unit (cubed). In the script and in the .pyp file however, the value would always be given in mm³.
<Parameter>
<Name>Volume</Name>
<Text>Volume</Text>
<Value>104553677431</Value>
<ValueType>Volume</ValueType>
</Parameter>
Angle
A parameter containing volume. In the palette the value is displayed in the current ALLPLAN angle unit. In the script and in the .pyp file however, the value would always be given in degrees.
<Parameter>
<Name>Angle</Name>
<Text>Angle</Text>
<Value>45</Value>
<ValueType>Angle</ValueType>
</Parameter>
Weight
A parameter containing weight. In the palette the value is displayed in the current ALLPLAN weight unit. In the script and in the .pyp file however, the value would always be given in kg.
<Parameter>
<Name>Weight</Name>
<Text>Weight</Text>
<Value>100</Value> <!--(1)!-->
<ValueType>Weight</ValueType>
</Parameter>
-
An additional default value for an imperial unit can be set with the tag:
<ImperialValue>
like:
Date
A parameter containing calendar date. In the script, the value is returned as a python built-in date object.
<Parameter>
<Name>Date</Name>
<Text>Date</Text>
<Value>date(2023,10,16)</Value>
<ValueType>Date</ValueType>
</Parameter>
Info
By adding an additional tag <ValueDialog>
ang setting it to DateDialog
you can allow the user to select the date from a dedicated date selection
dialog.
<Parameter>
<Name>DateWithDialog</Name>
<Text>Date</Text>
<Value>date(2023,10,16)</Value>
<ValueType>Date</ValueType>
<ValueDialog>DateDialog</ValueDialog> <!--(1)!-->
</Parameter>
-
After pressing the button, following dialog will appear
Additional tags
Min and max values
All the value types mentioned above (except for string) can be constrained with a maximum and
minimum value by adding the tags <MinValue>
and <MaxValue>
:
<Parameter>
<Name>Integer</Name>
<Text>Integer parameter</Text>
<Value>123</Value>
<ValueType>Integer</ValueType>
<MinValue>100</MinValue>
<MaxValue>200</MaxValue>
</Parameter>
These tags can contain conditions to create a dynamic minimal and/or maximal value.
This can be achieved with a Python expression. Functions from the math package are possible
(by coding math.xxx
).
Allow specific values
By adding the tag <ValueList>
it is possible to allow only certain values to be put in the edit field.
If this tag is set, the input value is checked against the values from <ValueList>
.
If the input value is not present there, it is matched to the closest value from the <ValueList>
.
Those allowed values can be provided as:
Slider
All of the above mentioned parameter types (except for string) can also be controlled with a slider like this:
<Parameter>
<Name>Integer</Name>
<Text>Integer slider</Text>
<Value>5</Value>
<ValueType>Integer</ValueType>
<ValueSlider>True</ValueSlider>
<MinValue>1</MinValue>
<MaxValue>10</MaxValue>
<IntervalValue>2</IntervalValue>
</Parameter>
Background color
The background color can be set with the tag <BackgroundColor>
. A typical use case
for it might be highlighting input fields in the property palette
to indicate, that the value is missing or incorrect.
The value for these tag must be a tuple with a red, green and blue part, e.g. like this (0, 255, 0)
.
To get the default background color, the tuple must be set to (-1, -1, -1)
.
<Parameter>
<Name>ExampleParameter</Name>
<Text>Integer</Text>
<Value>4711</Value>
<ValueType>Integer</ValueType>
<BackgroundColor>(0, 255, 0)</BackgroundColor>
</Parameter>
The background color value can also be set by a Python condition...
- Because the pyp file uses the xml syntax, we have to use
<
and>
for the<
and>
operators the xml syntax