Skip to content

Button

If some actions need to be triggered manually by the user of the PythonPart, a good idea to make it possible is to place a button in the palette. Because there are two texts needed (one for the button and one for the text on the left side of it) the button must be placed in a row. Here is a short example of how it should be done:

Button

<Parameter>
    <Name>ButtonRow</Name>
    <Text>Button</Text> <!--(1)!-->
    <ValueType>Row</ValueType> 

    <Parameter>
        <Name>Button</Name>
        <Text>ButtonText</Text> <!--(2)!-->
        <EventId>1000</EventId> <!--(3)!-->
        <ValueType>Button</ValueType>
    </Parameter>
</Parameter>
  1. This text will appear on the left side of a button...
  2. ...this, however, on the button itself. If it is too long, only the end will be displayed directly on the button. The complete text will be displayed as a tooltip.
  3. This value is passed to the script to determine, which button was clicked. If there are several buttons in the palette that should do the same job, you can assign the same EventId to them.

In order to control, which action should be triggered in the script, use the tag <EventId>. When a button is clicked, the function on_control_event is called and the the value of <EventId> tag is being given as (one of the) arguments. Here is how the implementation in a script can look like:

def on_control_event(build_ele: BuildingElement, event_id: int):
    if event_id == 1000:
        # do something
    elif event_id == 1001:
        # do something else
class InteractorClass():

    def on_control_event(self, event_id: int):
        if event_id == 1000:
            # do something
        elif event_id == 1001:
            # do something else

Example on GitHub

The full implementation of buttons is shown in the example Buttons ( PYP | PY)

Special button types

To open a web page directly when a button is clicked, provide the address within the <Value> tag to the parameter as follows:

<Parameter>
    <Name>Button</Name>
    <Text>ButtonText</Text>
    <EventId>1000</EventId>
    <ValueType>Button</ValueType>
    <Value>https://www.allplan.com</Value>
</Parameter>

Button with picture

To create a button with an icon from Allplan's internal image resources, set the <ValueType> to PictureResourceButton

Picture Resource Button

<Parameter>
    <Name>PictureResourceButton</Name>
    <Text>Button tooltip</Text><!--(1)!-->
    <EventId>1000</EventId>
    <Value>17027</Value> <!--(2)!-->
    <ValueType>PictureResourceButton</ValueType>
</Parameter>
  1. Tooltip text, which will appear by hovering over the button
  2. Provide the ID of the picture resource here. Click on the desired icon below - to copy the ID to your clipboard

      Page 1/0

    To create a button with your own icon from a .png file, set the <ValueType> to PictureButton

    Picture Button

    <Parameter>
        <Name>PictureButton</Name>
        <Text>Tooltip text</Text><!--(1)!-->
        <EventId>1000</EventId>
        <Value>ButtonImageReset16.png</Value><!--(2)!-->
        <ValueType>PictureButton</ValueType>
    </Parameter>
    
    1. Tooltip text, which will appear by hovering over the button
    2. Path must be relative to the .pyp file

    Multiple buttons

    To place several buttons in a row, each with an icon from Allplan's internal image resources, set the <ValueType> to PictureResourceButtonList

    Picture Resource Button List

    <Parameter>
        <Name>EdgeOffsetType</Name>
        <Text>Integer value list</Text><!--(1)!-->
        <Value>0</Value><!--(2)!-->
        <ValueList>0|1|2|3|4</ValueList><!--(3)!-->
        <ValueTextList><!--(4)!-->Zero at start|Major value at start|Start equal end|Major value at end|Zero at end</ValueTextList>
        <ValueList2>12151|12147|12149|12153|12145</ValueList2><!--(5)!-->
        <ValueType>PictureResourceButtonList</ValueType>
    </Parameter>
    
    1. This text will appear on the left side of the buttons
    2. The value defined here will be selected by default
    3. These integer values correspond with the buttons. They must be separated by |. Alternatively, use <EnumList> to define options of enumeration classes here (see below)
    4. These texts will appear as tooltip, when the user hovers the mouse over the corresponding button. You can localize them (learn more here)
    5. Provide the IDs of the picture resources separated by |. Click on the desired icon below - to copy the ID to your clipboard

        Page 1/0

      Example on GitHub

      The complete implementation is shown in the example PictureResourceButtonList ( PYP | PY).

      To place several buttons in a row, each with your own icon from a .png file, set the <ValueType> to PictureButtonList.

      Picture Button List

      <Parameter>
          <Name>IntegerValueList</Name>
          <Text>Integer value list</Text><!--(1)!-->
          <Value>1</Value><!--(2)!-->
          <ValueList>1|2|3</ValueList><!--(3)!-->
          <ValueTextList>Value=1|Value=2|Value=3</ValueTextList><!--(4)!-->
          <ValueList2>..\param01.png|..\param02.png|..\param03.png</ValueList2><!--(5)!-->
          <ValueType>PictureButtonList</ValueType>
      </Parameter>
      
      1. This text will appear on the left side of the buttons
      2. The value defined here will be selected by default
      3. These integer values correspond with the buttons. They must be separated by |. Alternatively, use <EnumList> to define options of enumeration classes here (see below)
      4. These texts will appear as tooltip, when the user hovers the mouse over the corresponding button. You can localize them (learn more here)
      5. The path for the images must be relative to .pyp file and separated with |

      Example on GitHub

      The complete implementation is shown in the example PictureButtonList ( PYP | PY).


      Alternatively to <ValueList> tag, where the values are integers, it is also possible to define the <EnumList> tag, where the values are options of any enumeration class.

      <Parameter>
          <Name>ShapeType</Name>
          <Text>Rectangle|Round/oval</Text>
          <Value>AllplanArchEle.VerticalOpeningShapeType.eRectangle</Value>
          <EnumList>AllplanArchEle.VerticalOpeningShapeType.eRectangle|
                    AllplanArchEle.VerticalOpeningShapeType.eCircle</EnumList>
          <ValueList2>AllplanSettings.PictResShapeType.eRectangle|
                      AllplanSettings.PictResShapeType.eCircle</ValueList2>
          <ValueType>PictureResourceButtonList</ValueType>
      </Parameter>
      

      Tip

      This kind of buttons are not intended to be an event trigger, because they do not have the value of <EventId> assigned to them. To use them as triggers, the implementation must be done within the modify_element_property function:

      def modify_element_property(build_ele: BuildingElement,
                                  name: str,
                                  value: Any):
      
          if name == "PictureButtonList1":
              if value == 0:
                  # do something
              elif value == 1:
                  # do something else
              elif value == 2:
                  # do something else
      
          return True
      

      Button for a reference point

      The value type RefPointButton is used to create a button for a selection of a reference point ID. This kind of button gives an integer value that corresponds with the selected point, as defined in the enumeration class RefPointButtonType.

      Reference Point Button

      <Parameter>
          <Name>RefPointId</Name>
          <Text>Reference point index</Text>
          <Value><!--(1)!-->AllplanPalette.RefPointPosition.eCenterCenter</Value>
          <ValueType>RefPointButton</ValueType>
          <EnumList2><!--(2)!-->AllplanPalette.RefPointButtonType.eCornersCenter</EnumList2>
      </Parameter>
      
      1. The default value can be defined as an option of RefPointButtonType class or as an integer
      2. Optionally, you can set, what reference points should be available. See possible options in the RefPointButtonType enumeration class.

      Material selection

      The value type MaterialButton is used to create a button for the selection of a material surface (.surf file) that can the assigned to a PythonPart for visualization purposes. After clicking the button, the dialog for custom surface selection will be opened.

      Material Button

      <Parameter>
          <Name>MaterialButton</Name>
          <Text>MaterialButton</Text>
          <Value>Glass</Value><!--(1)!-->
          <ValueType>MaterialButton</ValueType>
          <DisableButtonIsShown>True</DisableButtonIsShown><!--(2)!-->
      </Parameter>
      
      1. The <Value> stands for the name of the .surf file
      2. Optional By setting this tag to false you can disable the small button on the right, which is used to reset the input value.

      Additional tags

      Text size

      The size of the text appearing on the button can be controlled by an optional tag <FontStyle>

      Font Style

      <Parameter>
          <Name>Row1</Name>
          <Text>Font style = 0</Text>
          <ValueType>Row</ValueType>
      
          <Parameter>
              <Name>Button1</Name>
              <Text>Small text</Text>
              <EventId>1000</EventId>
              <ValueType>Button</ValueType>
              <FontStyle>0</FontStyle><!--(1)!-->
          </Parameter>
      </Parameter>
      
      1. Possible options for the tag are:

        Value Style
        0 small
        1 extra small
        2 large
      Placeholder