Enable and visible options

Sometimes it’s useful to disable or hide a control inside the property palette. To do this, the PythonParts framework offers the following options:

Disable or hide by Parameter tags

The following tags can be added to the parameter node to manage the enable and visible state of a control:

<Enable>False</Enable>
<Visible>CheckBox1 == True</Visible>

Because the pyp file uses the xml syntax, for the < and > operators the xml syntax &lt; and &gt; must be used.

The value for these tag can be:

  • a constant value like False, 0, …

  • a logical Python formula that includes other parameters like
    • CheckBox1 == True and CheckBox2 == True

    • Pen &gt; 10

    • RadioButtonValue in [1, 5]

  • a logical Python formula that includes access to the string table
    • ObjectName == __StringTable.get_string(“1220”, ‘Column’)

  • a logical Python formula that includes access to the list row
    • $list_row != HideListRow

    • StirrupList[$list_row].Select # (for a tuple field)

  • a logical Python formula that includes a check for the visibility of a parameter
    • __is_visible_control(“Length”) and Length > 0

  • a logical Python formula that includes a check to the input mode
    • __is_input_mode() # (returns False for PythonPart modification)

  • multi line Python condition returning False and True like

    <Visible>
      if Length &lt; 1000:
          return True:
    
      if Width &gt; 1000:
          return True
    
      return False
    <Visible>
    

The Python source code for the condition must be left aligned in the pyp file.

Disable or hide by functions

Depending on the complexity of the enable or visible condition, it may be useful to implement the condition of the enable or visible state in a function within the py file. Using the utility class ControlPropertiesUtil, the function must be assigned to the control defined by the parameter name as follows

def initialize_control_properties(build_ele     : BuildingElement,
                                  ctrl_prop_util: ControlPropertiesUtil,
                                  _doc          : AllplanElementAdapter.DocumentAdapter) -> None:
    """ initialize the control properties

    Args:
        build_ele     : building element
        ctrl_prop_util: control properties utility
        _doc          : document
    """

    def visible_length(...) -> bool:
        ...
        return ...

    def enable_length(...) -> bool:
        ...
        return ...

    ctrl_prop_util.set_visible_function("Length", visible_length)
    ctrl_prop_util.set_enable_function("Length", enable_length)

The parameter of the functions depend on the type of the parameter value:

value type

parameter

single value

()

value list

(row_index: int)

single named tuple

(field_name: str)

name tuple list

(row_index: int, field_name: str)

A use of the enable and visible functions is shown in the examples

…\etc\Examples\PythonParts\PaletteExamples\Visibility.pyp
…\etc\PythonPartsExampleScripts\PaletteExamples\Visibility.py
…\etc\Examples\PythonParts\PaletteExamples\NamedTuple.pyp
…\etc\PythonPartsExampleScripts\PaletteExamples\NamedTuple.py
…\etc\Examples\PythonParts\PaletteExamples\ValueList.pyp
…\etc\PythonPartsExampleScripts\PaletteExamples\ValueList.py