Object selection

Inside an interactor PythonPart it’s possible to start the standard Allplan selection interactor. This can by done as follows

post_element_selection = AllplanIFW.PostElementSelection()

AllplanIFW.InputFunctionStarter.StartElementSelect("Select the objects",
                                                    sel_setting, post_element_selection, True)

After this call it’s possible to use the entire Allplan selection functionalities such as selecting via point or area, setting filters, … for the selection of the required objects. In addition to the standard Allplan filters it,’s possible to start this selection interactor with a defined filter.

The implementation of the filter can look like

class Object3DFilter():
    """ implementation of the 3D object filter """

    def __call__(self, element: AllplanElementAdapter.BaseElementAdapter):
        """ execute the filtering

        Args:
            element: element to filter

        Returns:
            element fulfills the filter: True/False
        """

        return element.Is3DElement()

sel_query   = AllplanIFW.SelectionQuery([Object3DFilter()])
sel_setting = AllplanIFW.ElementSelectFilterSetting(sel_query, True)

The filter class is a standard Python class with a required __call__ member function that is called by Allplan for filtering.

When filtering by object type, the type of the object can be used for filter creation. The creation of the filter can be done as follows

type_query = AllplanIFW.QueryTypeID(AllplanIFW.WallTier_TypeUUID)

sel_query   = AllplanIFW.SelectionQuery(type_query)
sel_setting = AllplanIFW.ElementSelectFilterSetting(sel_query, True)

As parameter for the type ID query also a Python list with the UUIDs is possible

After the selection interactor has been started, all mouse messages are processed by this interactor. The inputs in the property palette are handled as before in the PythonPart interactor. If the selection is to be canceled, e.g. by a button click in the property palette, this can be done by calling the function

if post_element_selection:
    AllplanIFW.InputFunctionStarter.RemoveFunction()

In the above code the running interactor is checked by the presence of the member post_element_selection.

After the selection is complete, the mouse messages are processed again by the PythonPart interactor. This can be used as follows to get the selected elements

if post_element_selection:
    objects = post_element_selection.GetSelectedElements(coord_input.GetInputViewDocument())

    post_element_selection = None

The complete documentation of the members from the PostElementSelection, InputFunctionStarter, SelectionQuery, ElementSelectFilterSetting and InputFunctionStarter class can be found here:

and a use of the selection classed is implemented in the example

…\etc\Examples\PythonParts\ModelObjectExamples\SelectionExamples\SelectObjectsWith3DGeometry.pyp
…\etc\PythonPartsExampleScripts\ModelObjectExamples\SelectionExamples\SelectObjectsWith3DGeometry.py