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.

Info

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_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. 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!

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

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.

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 via the method 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)))

The method GetPureArchitectureElementGeometry gets 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)))

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_adapter.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.

Example

Imagine your PythonPart allows the user to select an existing text element in the viewport and you would like to read its content and font. We assume, you have set up a filter as described here and therefore the result of the selection will be a BaseElementAdapter object of type TextBlock_TypeUUID.

First, you need to get the TextElement out of the BaseElementAdapter. Use the GetElement for that.

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

Now you have the TextElement object. You can access all its properties:

>>> text_element.Text
"Foo"
>>> text_element.TextProperties.Font
21

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 Remarks
3D object ModelElement3D
Beam BeamElement
Bar placement in line BarPlacement Use GetPlacementMatrix to determine the position of the first rebar in the placement. GetStartPoint does not deliver the start point in case of an existing placement.
Bar placement in rotation BarPlacement
Column ColumnElement
Curve (line, polyline, etc.) ModelElement2D
Curve 3-dimensional ModelElement3D
Element group ❌
Fixture FixturePlacementElement
Hatch ❌
Label LabelElement
Opening (niche, recess) ❌
Reinforcement placement ❌
Slab SlabElement
Slab opening SlabOpeningElement
Smart symbol MacroPlacementElement
Wall, straight WallElement
User def. archit. element ❌
Text TextElement

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

Placeholder