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 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:
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.
If selection is done in the ground view, the method returns a Polygon2D.
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)!
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
>>> 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.
The method GetPureArchitectureElementGeometry gets the model geometry1 of an architectural component without considering the cut-outs.
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.
---
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:
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
Attributes:
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
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.
- 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:
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:
- In a standard PythonPart it is given to you directly by the PythonPartsFramework as argument of some functions, e.g. in modify_control_properties.
- 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.
- By a calling GetDocument on a BaseElementAdapter object.
-
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. ↩↩↩
-
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. ↩