Skip to content

Read access

Accessing the existing elements in the DF has to be done in two steps.

  • Get the element adapter


    This gives access general element data, common for all types of ALLPLAN elements.

  • Get the python object


    This gives access all specific element data, like axis of a wall or placement matrix of a macro

Info

To get the python object, you first need the element adapter.

Element adapter

When accessing the elements that exists in a DF (e.g. through selection), Python API returns a BaseElementAdapter. This is to avoid problems in case the internal CAD data structure of ALLPLAN should be changed in the future.

Tip

If you want to get all the elements from the currently opened DFs, you can simply call the SelectAllElements.

Although the element adapter is not the python object, that you would use to create the selected element and it does not contain all the information about the element, it provides the access to some general data, common for all type of elements:

Descriptive data

The table below shows the most relevant descriptive meta-data, that you can access through BaseElementAdapter, together with the method to use.

Data Method
Name, with which the element is described in the ALLPLAN UI GetDisplayName()
DF number GetDrawingfileNumber()
ElementAdapterType used e.g. for filtering GetElementAdapterType()
UUID of the element1 GetElementUUID()
UUID of the model element GetModelElementUUID()

Example

>>> base_element_adapter.GetDisplayName()
Wall, straight

>>> base_element_adapter.GetDrawingfileNumber()
1

>>> base_element_adapter.GetElementAdapterType().GetTypeName()
Wall_TypeUUID

>>> base_element_adapter.GetElementUUID()
bcdb12de-00fe-4ed8-b237-af6cb158adf3

Base geometry

Accessing the geometry can be done with multiple methods, depending on the desired result. In this chapter we will be considering a wall with an opening, like this:

Wall

Warning

Since the wall consists of tiers, the geometry must be accessed via the wall tiers!

Info

The following types of geometry are relevant only for architectural elements, since they can have different representation in ground view or can have openings as independent elements (e.g. window). All other elements have only one type of geometry, described under the tab General geometry.

Calling GetGeometry() returns the general geometry of the element. In case of a general element2, its geometry is returned always in the same way, regardless of the point of view.

In case of an architectural components the result depends on the projection of the view used during the selection.

Wall ground view

If selection is done in the ground view, the method returns a Polygon2D.

>>> base_element_adapter.GetGeometry()
Polygon2D(
    Count(5)
    Points(
        (0, 0)
        (5000, 0)
        (5000, 240)
        (0, 240)
        (0, 0)))

Wall isometric view

If the selection is done in an isometric view, the method returns the 3D wall geometry as Polyhedron3D. The returned geometry will not consider the cut-outs (windows, recesses)!

>>> base_element_adapter.GetGeometry()
Polyhedron3D(
    Type(3)
    IsNegative(0)
    PartsCount(1)
    EdgeCount(12)
    FaceCount(6)
    VertexCount(8)
    Vertices(
        (0, 0, 0)
        (5000, 0, 0)
        (5000, 240, 0)
        (0, 240, 0)
        (0, 0, 2500)
        (5000, 0, 2500)
        (5000, 240, 2500)
        (0, 240, 2500)))

Calling GetModelGeometry() returns the model geometry1 of the element, including the cut-out of openings. The result is always the same, regardless of the point of view.

In case of our wall with an opening the result would look like this

Wall isometric view

>>> base_element_adapter.GetModelGeometry()
Polyhedron3D(
    Type(3)
    IsNegative(0)
    PartsCount(1)
    EdgeCount(24)
    FaceCount(10)
    VertexCount(16)
    Vertices(
        (0, 240, 0)
        (0, 0, 0)
        (2000, 0, 0)
        (2000, 240, 0)
        (3010, 240, 0)
        (3010, 0, 0)
        (5000, 0, 0)
        (5000, 240, 0)
        (0, 0, 2500)
        (0, 240, 2500)
        (5000, 240, 2500)
        (5000, 0, 2500)
        (3010, 0, 2010)
        (2000, 0, 2010)
        (2000, 240, 2010)
        (3010, 240, 2010)))

Architectural components have two different representations: one in ground view and one in an isometric view. The first one can be accessed by calling GetGroundViewArchitectureElementGeometry(). It does not consider cut-outs, like window opening or recess.

Wall ground view

>>> base_element_adapter.GetGroundViewArchitectureElementGeometry()
Polygon2D(
    Count(5)
    Points(
        (0, 0)
        (5000, 0)
        (5000, 240)
        (0, 240)
        (0, 0)))

Calling GetPureArchitectureElementGeometry() returns the model geometry1 of an architectural component without considering the cut-outs.

>>> base_element_adapter.GetPureArchitectureElementGeometry()
Polyhedron3D(
    Type(3)
    IsNegative(0)
    PartsCount(1)
    EdgeCount(12)
    FaceCount(6)
    VertexCount(8)
    Vertices(
        (0, 0, 0)
        (5000, 0, 0)
        (5000, 240, 0)
        (0, 240, 0)
        (0, 0, 2500)
        (5000, 0, 2500)
        (5000, 240, 2500)
        (0, 240, 2500)))

Hierarchy

Model elements in ALLPLAN are organized in a hierarchy tree. You can access the elements from the hierarchy, using BaseElementAdapterParentElementService and BaseElementAdapterChildElementsService.

Example

A single layer wall with a door opening (as shown on the right) is represented in the DF with several elements organized in a hierarchy like this:

Wall isometric view

Wall_TypeUUID
├── AttributeContainer_TypeUUID
├── WindowDoor_TypeUUID
   └── WindowDoorTier_TypeUUID
       ├── AttributeContainer_TypeUUID
       ├── WindowDoorReveal_TypeUUID
          └── OpeningPartDoor_TypeUUID
              └── AttributeContainer_TypeUUID
       └── DoorSill_TypeUUID
└── WallTier_TypeUUID
    ├── AttributeContainer_TypeUUID
    ├── WallAxis_TypeUUID
       └── WallAxisLine_TypeUUID
    └── WindowDoorTier_TypeUUID
        ├── AttributeContainer_TypeUUID
        ├── WindowDoorReveal_TypeUUID
           └── OpeningPartDoor_TypeUUID
               └── AttributeContainer_TypeUUID
        └── DoorSill_TypeUUID
Relationship diagram
erDiagram
    Wall ||--|{ Wall_layer : ""
    Wall ||--o{ Door_opening : ""
    Door_opening ||--|{ Door_opening_layer : ""
    Wall_layer ||--o{ Door_opening_layer : ""
    Wall_layer ||--|| Wall_axis: ""
    Door_opening_layer ||--o| Door_reveal : ""
    Door_opening_layer ||--o| Door_sill : ""
    Wall_axis ||--|| Wall_axis_line: ""
    Door_reveal ||--o| Door: ""

    Wall {
        ElementType Wall_TypeUUID
        Geometry None
        HasAttributes Yes
    }
    Wall_layer["Wall layer"] {
        ElementType WallTier_TypeUUID
        Geometry Polygon2D
        HasAttributes Yes
    }

    Wall_axis["Wall axis"] {
        ElementType WallAxis_TypeUUID
        Geometry None
        HasAttributes No
    }

    Wall_axis_line["Wall axis line"]{
        ElementType WallAxisLine_TypeUUID
        Geometry Line2D
        HasAttributes No
    }

    Door_opening["Door opening"] {
        ElementType WindowDoor_TypeUUID
        Geometry None
        HasAttributes No
    }

    Door_opening_layer["Door opening layer"] {
        ElementType WindowDoorTier_TypeUUID
        Geometry Line2D
        HasAttributes Yes
    }

    Door_reveal["Door reveal"] {
        ElementType WindowDoorReveal_TypeUUID
        Geometry Polyline2D
        HasAttributes No
    }

    Door_sill["Door sill"] {
        ElementType DoorSill_TypeUUID
        Geometry Polyline2D
        HasAttributes No
    }

    Door["Door"] {
        ElementType OpeningPartDoor_TypeUUID
        Geometry None
        HasAttributes No
    }

When you introduce a selection without any additional filters and the user picks up the wall, you will likely get the wall layer (element adapter of type WallTier_TypeUUID).

To go one level up in the entity hierarchy (see diagram above) and get the whole wall (element adapter of type WallTier_TypeUUID), call GetParentElement():

>>> AllplanEleAdapter.BaseElementAdapterParentElementService.GetParentElement(selected_wall_tier)
Wall, straight

To go one level down in the entity hierarchy and get the direct child elements of the wall layer, call GetChildModelElements():

>>> for child in AllplanEleAdapter.BaseElementAdapterChildElementsService.GetChildModelElements(selected_wall_tier, False):
...     print(child.GetElementAdapterType().GetTypeName())
WallAxis_TypeUUID
WindowDoorTier_TypeUUID

To go down all the hierarchy levels and get the child elements, grand-child elements, etc... call GetChildModelElementsFromTree():

>>> for child in AllplanEleAdapter.BaseElementAdapterChildElementsService.GetChildModelElementsFromTree(selected_wall_tier):
...     print(child.GetElementAdapterType().GetTypeName())
WallAxis_TypeUUID
WallAxisLine_TypeUUID
WindowDoorTier_TypeUUID
WindowDoorReveal_TypeUUID
OpeningPartDoor_TypeUUID
DoorSill_TypeUUID

To get a list of all window and door openings in this wall, you need to:

  • go one level up in the hierarchy and get the adapter of the whole wall (Wall_TypeUUID)
  • get its child elements, but only these of type WindowDoor_TypeUUID

This can be implemented like:

# get the parent of the tier - the whole wall
wall = AllplanEleAdapter.BaseElementAdapterParentElementService.GetParentElement(selected_wall_tier)

# filter all its child elements to get only these of type WindowDoorTypeUUID
all_child_elements = AllplanEleAdapter.BaseElementAdapterChildElementsService.GetChildModelElements(wall, True)
window_door_filter = AllplanIFW.SelectionQuery([AllplanIFW.QueryTypeID(AllplanEleAdapter.WindowDoor_TypeUUID)])
openings = list(filter(window_door_filter, all_child_elements)) #(1)!
  1. SelectionQuery object is callable and returns True, when the given BaseElementAdapter is of given type. Therefore, it can be used directly as a filter function in the python built-in filter object .

Example on GitHub

You can explore the elements hierarchy by using the example ShowHierarchy ( PYP | PY). Start the example and select any model element, whose hierarchy you would like to explore. The hierarchy tree will be printed in the trace and the element you clicked will be marked yellow.

Attributes

To read the attributes of a model element, call GetAttributes(). You'll get a list of pairs, like (attribute ID, attribute value). We recommend to turn it directly into a dictionary, like:

>>> attr_list = dict(base_element_adapter.GetAttributes(AllplanBaseEle.eAttibuteReadState.ReadAll))
>>> attributes = dict(attr_list) #(1)!
>>> for id, value in attributes:
...    print(f"{id} {AllplanBaseElements.AttributeService.GetAttributeName(doc, id)} = {value}")
10 Allright_Comp_ID = 0019Wal0000000398
12 Component ID = 398
49 Status = New building
83 Code text =
120 Calculation mode = m²
209 Trade = Concreting work
214 Component =
220 Length = 5.0
221 Thickness = 0.24
222 Height = 2.5
226 Net volume = 3.0
229 Area = 12.5
498 Object_name = Wall
508 Material =
683 Ifc ID = 2lHXKxsQH3WgilI_LmUCVc
  1. This way you can easily access desired attribute, like:

    >>> attributes[220]
    5.0
    

Tip

To read and modify the attributes of adapters, you can use the ElementsAttributeService. Refer to this chapter to learn more.

Format properties

To read the format properties from the element adapter, call GetCommonProperties():

>>> element_adapter.GetCommonProperties()
CommonProperties(
   Color                       (1)
   Layer                       (3800)
   Stroke                      (1)
   Pen                         (1)
   ...
   DrawOrder                   (0))

To learn more about format properties, refer to this article.

Getting python object

For some element types, it is possible to get an instance of the python object representing the selected element. This is particularly useful, when you need to get information specific for a certain element type (e.g. thickness of a wall layer).

Info

Please note, that we are constantly developing the Python API. At the moment, you cannot get a corresponding Python API object from all types of element adapters. A good overview, what is possible and what is not, are the tables with model element types in this article.

Example

Your PythonPart allows the user to select an existing text element in the viewport. You would like to read its content and font. Set up a filter as described here to make sure, the result of the selection is a BaseElementAdapter of type TextBlock_TypeUUID:

>>> type(selected_text)
NemAll_Python_IFW_ElementAdapter.BaseElementAdapter
>>> adapter.GetElementAdapterType().GetTypeName()
'TextBlock_TypeUUID'

Now get the instance of TextElement from the BaseElementAdapter by calling GetElement(). Then, you can access all the text properties of text_element like:

>>> text_element = AllplanBaseEle.GetElement(selected_text) #(1)!
>>> text_element.Text
"Foo"
>>> text_element.TextProperties.Font
21
  1. You can also use the GetElements function if you allow selection of multiple elements (in this case you get a BaseElementAdapterList)

Example on GitHub

To test, whether a python object can be accessed with GetElements or to just see the full implementation of the methods of BaseElementAdapter, have a look at the example ShowObjectInformation ( PYP | PY).

Document adapter

The DocumentAdapter object represents the currently opened document. Even when multiple DFs are opened, they are all represented by one DocumentAdapter. This object is needed for the access to the ALLPLAN model. Depending on the contract you implement in your script, you obtain it differently:

  1. In a standard PythonPart it is given to you directly by the PythonPartsFramework as argument of some functions, e.g. in modify_control_properties.
  2. In an interactor PythonPart or in a script object you have access to the CoordinateInput object (the framework gives it to you when initializing the interactor or script object). You can get the DocumentAdapter from it by calling GetInputViewDocument.
  3. By a calling GetDocument on a BaseElementAdapter object.

  1. Some type of elements are represented differently in different type of views. E.g. a wall is represented with a polyhedron in a 3D view, but with a polyline and a hatch in the ground view. Element UUID is the ID of the wall's representation, i.e. it varies depending on the view. Model Element UUID is the UUID of the wall itself, and is therefore consistent. In elements without this behavior, Element UUID and Model Element UUID are equal. 

  2. Element adapter is a general element, when the method IsGeneralElement´ called on the adapter returns True. This is the case e.g. for lines (2D and 3D), hatches, fillings or 3D objects. This is not the case for architectural components or reinforcement elements. 

Placeholder