Skip to content

Parameters

Parameter node

The node <Parameter> is used to define the parameter of the PythonPart, as well as the layout and controls of the property palette. The order of the <Parameter> nodes within <Page> node decides the order of the controls in the tab control of the property palette. Here is a basic example of a parameter:

<Parameter>
    <Name>Integer</Name>
    <Text>Integer parameter</Text>
    <Value>123</Value>
    <ValueType>Integer</ValueType><!--(1)!-->
</Parameter>
  1. Depending on the required control type for the input of the parameter value, a corresponding value type must be set. Please refer to the subchapters to learn, what types of controls are available.

ParameterInteger

For the full list of tags, which can be included under <Parameter> with their explanation please refer to the chapter all tags.

Address the parameter value in script

For each parameter, an object of type ParameterProperty is being created and stored as a property in the BuildingElement object. This again is being passed as an argument to the functions build in the script (learn more about them here or here). The name of the property is the same, as the parameter name.

Example

Let's assume we defined a parameter Integer in the .pyp file, just as in the example above. When a PythonPart is started, the create_element function is called and the BuildingElement object is passed to it by the PythonPart framework. The parameter value can be addressed within this function as follows:

def create_element(build_ele: BuildingElement, #(1)!
                   doc: AllplanElementAdapter.DocumentAdapter):

    my_integer = build_ele.Integer.value #(2)!
    print("The value of the integer parameter is: " + str(my_integer))
  1. This object holds our parameter in a property named the same as the parameter, so calling build_ele.Integer will get us the parameter as ParameterProperty object.
  2. To get the value, we simply must refer to the value property of the ParameterProperty object
Result in Allplan trace window
The value of the integer parameter is: 123

Localization

The text that appears in the property palette (<Text>), as well as the default value of a parameter (<Value>) can both be localized by supplying the tags <TextId> and <ValueTextId> respectively.

<Parameter>
    <Name>String</Name>
    <Text>String parameter</Text>
    <Value>This is a string</Value>
    <ValueType>String</ValueType>
    <TextId>1001</TextId>
    <ValueTextId>1002</ValueTextId><!--(1)!-->
</Parameter>
  1. Of course localizing the default value only makes sense in case of a string parameter

Please refer to the chapter string resources to learn more about how to build the .xml file for localizing a PythonPart.

Show the same parameter on multiple pages

A <Parameter> with the same name and values can occur on multiple pages inside the pyp-file. This makes it possible to have a control for a parameter on different pages within the property palette.

Example

An example of using a parameter on multiple pages is shown in AllControls

  • …\etc\Examples\PythonParts\PaletteExamples\AllControls.pyp
  • …\etc\PythonPartsExampleScripts\PaletteExamples\AllControls.py

Set up the size

If a control is in a row, the height and width can be defined by the optional tags <HeightInRow> and <WidthInRow>. The values must be provided in pixels. The size values can be used, for example, to make the image in a button control more visible.

Control size

Set up the text style

The style of the text displayed on the left side can be controlled with the tag <FontFaceCode>

Option Description
0 normal
1 bold
2 italic
4 underline
<Parameter>
    <Name>Integer</Name>
    <Text>Integer parameter</Text>
    <Value>123</Value>
    <ValueType>Integer</ValueType>
    <FontFaceCode>2</FontFaceCode>
</Parameter>

Text style

Persistency

Using the optional tag <Persistent> it is possible to control the persistency of the parameter. This means, whether the parameter should be stored in the favorite file (.pyv file) and/or in the model in the PythonPart itself.

Setting Description
No No persistent parameter
ModelAndFavorite The parameter is stored in the PythonPart as well as in the favorite file
Model The parameter is stored only in the PythonPart
Favorite The parameter is stored only in the favorites file
<Parameter>
    <Name>Integer</Name>
    <Text>Integer parameter</Text>
    <Value>123</Value>
    <ValueType>Integer</ValueType>
    <Persistent>Model</Persistent>
</Parameter>