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 Python API will return a BaseElementAdapter. This is the case e.g., during the element selection. The reason why the elements are represented in this way is to avoid problems, in case the internal CAD data structure of Allplan should be changed in the future.

Abstract

Refer to this article to learn more how to implement the element selection into your interactor PythonPart.

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

The element adapter provides the access to some general data, common for all type of Allplan elements:

Descriptive data

BaseElementAdapter provides methods for accessing the data describing an element. In the table below you find the most important ones together with the methods 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.GetDisplayName()
Wall, straight

>>> base_element.GetDrawingfileNumber()
1

>>> base_element.GetElementAdapterType().GetTypeName()
Wall_TypeUUID

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

Base geometry

Accessing the geometry can be done with multiple methods, depending on the desired result. Whereas the geometry of general 2D or 3D elements is defined straight forward, the geometry of architectural elements can be read in several different ways, depending on whether we want to take openings into account or not. 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!

General geometry

The method GetGeometry returns the 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, like our wall, the result depends on the projection of the view used during the selection.

Example

input
base_element.GetGeometry()

Wall ground view

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

output
Polygon2D(
    Count(5)
    Points(
        (0, 0)
        (5000, 0)
        (5000, 240)
        (0, 240)
        (0, 0)))

Wall isometric view If the same wall was selected in an isometric view, the method will return the 3D wall geometry as Polyhedron3D. The returned geometry will not consider the cut-outs such as window opening or recess!

output
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)))

Model geometry

The method 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.

Example

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

Wall isometric view

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)))

Ground view geometry

Architectural components are represented differently in ground view and in an isometric view. This special 2D geometry representation in the ground view can be accessed via the method GetGroundViewArchitectureElementGeometry. This method does not consider cut-outs, like window opening or recess.

Example

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

Wall ground view

Polygon2D(
    Count(5)
    Points(
        (0, 0)
        (5000, 0)
        (5000, 240)
        (0, 240)
        (0, 0)))

Pure architecture geometry

The method GetPureArchitectureElementGeometry gets the model geometry1 of an architectural component without considering the cut-outs.

Example

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

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)))

Parent and child elements

Model elements in Allplan are organized in hierarchy. To access the elements from the hierarchy we can use the service classes BaseElementAdapterParentElementService and BaseElementAdapterChildElementsService. These classes provide us methods to get the adapters of parent element or child elements respectively.

Example

Our wall with a door opening is represented in Allplan with several elements organized in one hierarchy. Depending on the selection filter (more about it this chapter) we get different elements from the hierarchy as a result of element selection.

Wall isometric view

---
title: Elements hierarchy
---
erDiagram
    Wall ||--|{ Wall_layer : ""
    Wall ||--o{ Door_opening : ""
    Door_opening ||--|{ Door_opening_layer : ""
    Wall_layer ||--o{ Door_opening_layer : ""
    Door_opening_layer ||--|| Door_reveal : ""

    Wall {
        ElementType Wall_TypeUUID
    }
    Wall_layer {
        ElementType WallTier_TypeUUID
    }
    Door_opening {
        ElementType Door_TypeUUID
    }
    Door_opening_layer {
        ElementType DoorTier_TypeUUID
    }
    Door_reveal {
        ElementType DoorReveal_TypeUUID
    }

Assuming no selection filter is set, and the user clicked on the wall, an adapter to wall layer is returned. To get the adapter to the wall element, we must use the GetParentElement method:

wall_adapter = AllplanElementAdapter.BaseElementAdapterParentElementService.GetParentElement(wall_tier_adapter)

Attributes

To read the attributes of a model element, you can use the method GetAttributes. It will return the attributes as a list of tuples (attribute ID, attribute value).

Example

print("Attributes:")

for attribute in base_element.GetAttributes(AllplanBaseEle.eAttibuteReadState.ReadAll):
    print("\t", attribute[0], AllplanBaseEle.AttributeService.GetAttributeName(doc, attribute[0]), "=", attribute[1])
Attributes:
    10 Allright_Comp_ID = 0019Wal0000000398
    12 Component ID = 398
    49 Status = New building
    83 Code text =
    120 Calculation mode = 
    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

Tip

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

Common properties

The common properties defines how the element is drawn in the viewport. You can learn more about this object in this article. The common properties can be read from the adapter with the function GetCommonProperties. It will return a CommonProperties object.

Getting python object

For some elements it is possible to get an instance of a Python class, that represents the selected object in the API. This is particularly useful, when you need to get information, that is specific for a certain element type.

For example, to get the content of the selected text, you need to read the property Text from the TextElement object. But first, you need to get the TextElement from BaseElementAdapter. This can be done using the GetElements function.

adapter_list = AllplanElementAdapter.BaseElementAdapterList([text_adapter]) #(1)!
objects = AllplanBaseEle.GetElements(adapter_list) #(2)!
  1. Let's assume, text_adapter contains a BaseElementAdapter of type TextBlock_TypeUUID. GetElements needs a BaseElementAdapterList so we construct one
  2. The result will be a one-element list containing the TextElement

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. Below we present a short overview of the most essential Allplan elements and the class, whose instance you get (or not) when using GetElements function.

Allplan element Python object
3D object ModelElement3D
Beam BeamElement
Column ColumnElement
Curve (line, polyline, etc.) ModelElement2D
Curve 3-dimensional ModelElement3D
Element group ❌
Fixture FixturePlacementElement
Hatch ❌
Label LabelElement
Opening (niche, recess) ⚠ SlabOpeningElement only
Reinforcement placement ❌
Slab SlabElement
Slab opening SlabOpeningElement
Smart symbol MacroPlacementElement
Wall, straight WallElement
User def. archit. element ❌
Text TextElement

Example

To test, whether a python object can be accessed with GetElements or to just see the full implementation of the methods of BaseElementAdapter, refer to the example ShowObjectInformation, located in:

  • …\etc\Examples\PythonParts\ModelObjectExamples\General\ShowObjectInformation.pyp
  • …\etc\PythonPartsExampleScripts\ModelObjectExamples\General\ShowObjectInformation.py

  1. Some type of elements are represented differently in different type of views. This is E.g. a wall is represented with a polyhedron in 3D view, but with a polyline and a hatch in 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.