Skip to content

Element adapter

When accessing the elements that exists in a document (e.g., through element selection), Python API will return BaseElementAdapter objects, usually organized in a BaseElementAdapterList. This is a general element class created as adapter to avoid problems, in case the internal CAD data structure should be changed in the future. The idea of an adapter is not to provide the full access to a model object, but to some general data such as:

Note

Note that the methods of the class BaseElementAdapter provide the read-only access to the model elements.

Descriptive data

BaseElementAdapter class provides methods for accessing the data describing an object. Information like e.g.:

  • Name under which the object appears in the Allplan UI e.g., Column, general 3D object, line, etc. can be get with the GetDisplayName method

    Note

    The display names are localized and depends on the language version of Allplan being used!

  • DF number can be get with the GetDrawingfileNumber method.

  • ElementAdapterType can be get with the GetElementAdapterType method. This object describes the type of the element. Every element type in Allplan has a unique name and GUID. All types are listed in the IFW_ElementAdapter module.
  • UUID can be get with the GetModelElementUUID method. UUID is an identifier of a model element and is unique for each element in the model.

Example

input
print("Name:                ", base_element.GetDisplayName())
print("Drawing file number: ", base_element.GetDrawingfileNumber())
print("Element adapter type:", base_element.GetElementAdapterType().GetTypeName())
print("Model element UUID:  ", base_element.GetModelElementUUID())
print("Is 3D element:       ", base_element.Is3DElement())
output
Name:                 Wall, straight
Drawing file number:  1
Element adapter type: Wall_TypeUUID
Model element UUID:   bcdb12de-00fe-4ed8-b237-af6cb158adf3
Is 3D element:        True

Base geometry

Accessing the geometry can be done with multiple methods, depending on the desired result. Whereas the geometry of general 2D or 3D objects 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 selected base geometry object e.g., in case of object selection by the cursor. In case of a base 2D or 3D object like line or cube, its geometry is returned always in the same way, as an object of NemAll_Python_Geometry module, regardless of the point of view.

In case of an architectural object, 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 object representing the wall.

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 object. 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 geometry of the object as it is represented in the Allplan model, 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 objects 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 3D geometry of an architectural element 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 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

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 can be read by the function GetCommonProperties. It will return a CommonProperties object. Refer to this chapter to learn more about it.