Skip to content

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 String

<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 Integer

<Parameter>
    <Name>Integer</Name>
    <Text>Integer</Text>
    <Value>123</Value>
    <ValueType>Integer</ValueType>
</Parameter>

Double

A parameter containing a floating-point value.

Parameter Double

<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 Length

<Parameter>
    <Name>Length</Name>
    <Text>Length</Text>
    <Value>4711</Value> <!--(1)!-->
    <ValueType>Length</ValueType>
</Parameter>
  1. An additional default value for an imperial unit can be set with the tag <ImperialValue> like:

    <ImperialValue>4'6"</ImperialValue>
    

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 Area

<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 Volume

<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 Angle

<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 Weight

<Parameter>
    <Name>Weight</Name>
    <Text>Weight</Text>
    <Value>100</Value> <!--(1)!-->
    <ValueType>Weight</ValueType>
</Parameter>
  1. An additional default value for an imperial unit can be set with the tag: <ImperialValue> like:

    <ImperialValue>100lb</ImperialValue>
    

Date

A parameter containing calendar date. In the script, the value is returned as a python built-in date object.

Parameter Date

<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 date with dialog

<Parameter>
    <Name>DateWithDialog</Name>
    <Text>Date</Text>
    <Value>date(2023,10,16)</Value>
    <ValueType>Date</ValueType>
    <ValueDialog>DateDialog</ValueDialog> <!--(1)!-->
</Parameter>
  1. After pressing the button, following dialog will appear

    Parameter Date Dialog

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).

<MinValue>0 if WithOutBorder else 100</MinValue>
<MaxValue>
    if WithOutBorder:
        return 0
    else:
        return 100
</MaxValue>

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:

<ValueList>1.0|2.0|3.0|4.0</ValueList>
<ValueList>[value for value in range(0, RangeEnd + 1 , 5)]</ValueList>
<ValueList>
    if HeightDimension == 1:
        return "700.|725|750|775"
    elif HeightDimension == 2:
        return "800|825|850|875"
    else:
        return "900|925|950|975"
</ValueList>

Slider

All of the above mentioned parameter types (except for string) can also be controlled with a slider like this:

Parameter Integer as Slider

<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).

ParameterBackgroundColor

<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...

<BackgroundColor>(0, 0, 255) if Double &lt;<!--(1)!--> 50 else (-1, -1, -1)</BackgroundColor>
  1. Because the pyp file uses the xml syntax, we have to use &lt; and &gt; for the < and > operators the xml syntax
<BackgroundColor>
    if Double &lt; 1000:
        return (0, 255, 0)
    else
        return (0, 0, 255)
</BackgroundColor>

Example on GitHub

For the full implementation, check out the example EditControls ( PYP | PY)

Placeholder