Skip to content

Element attributes

In this chapter we focus on managing the attributes appended to model elements. This means attributes of elements like walls, slabs, reinforcement or 2D-Lines or 3D-solids. This chapter applies also to model elements without geometrical representation like element groups. Handling of project attributes is described in a separate chapter.

Create elements with attributes

Every object, that can be created in a DF, like wall or 3d object, is a child object of the AllplanElement class. In all those kind of objects, attributes are organized in a data structure represented by the Attributes object. It is composed of usually one AttributeSet object, which in turn is composed usually several Attribute objects, like AttributeString or AttributeInteger (depending on the value type of the attribute). The relationships are shown on the graph below.

classDiagram
    direction BT

    class AllplanElement{
        <<Abstract>>
        Attributes Attributes
        CommonProperties CommonProperties
        Any GeometryObject
        list[LabelElement] LabelElements
    }
    class WallElement {
        WallProperties
    }
    class ModelElement3D {
        TextureDefinition TextureDefinition
        TextureMappingProperties TextureMapping
    }
    class Attributes{
        list[AttributeSet] AttributeSets
    }
    class AttributeSet{
        list[Attribute] Attributes
    }
    class Attribute{
        <<Abstract>>
    }

    class AttributeString{
        int id
        str value
    }
    class AttributeInteger{
        int id
        int value
    }
    class AttributeDouble{
        int id
        float value
    }
    class AttributeDate{
        int id
        int day
        int month
        int year
    }
    class AttributeEnum{
        int id
        int value
    }

    AttributeString --|> Attribute
    AttributeInteger --|> Attribute
    AttributeDouble --|> Attribute
    AttributeDate --|> Attribute
    AttributeEnum --|> Attribute

    Attribute "*" --o "1" AttributeSet

    AttributeSet "1..*" --o "1" Attributes

    Attributes "0..1" --o "*" AllplanElement

    WallElement --|> AllplanElement
    ModelElement3D --|> AllplanElement

Example

In this example we have a model_element which is an AllplanElement object and we want to append two attributes to it:

  • Status (N° 49) of New building
  • Fire risk factor (N° 1398) of A2
attr_fire_risk_factor = AllplanBaseElements.AttributeString(1398, "A2") #(1)!
attr_status = AllplanBaseElements.AttributeEnum(49, 0) #(2)!

attr_set = AllplanBaseElements.AttributeSet([attr_fire_risk_factor, attr_status])

attributes = AllplanBaseElements.Attributes([attr_set])

model_element.SetAttributes(attributes)
  1. The attribute Fire risk factor has a value type string, that is why we have to instantiate the AttributeString object.
  2. The attribute Status is an enumeration attribute, where the value New building has the 0 key.

Using PythonPart framework

As shown in the example above, appending an attribute to an AllplanElement requires the knowledge about value type of the attribute we want to append. The easier way is to use the BuildingElementAttributeList, which will do part of the work for us. This class offers methods, which can create an attribute list by:

  • adding attributes explicitly using ID and value,
  • retrieving attributes from the property palette parameters.

Example

Just as in the example before, we have a model_element which is an AllplanElement object and we want to append two attributes to it:

  • Status (N° 49) of New building
  • Fire risk factor (N° 1398) of A2
attribute_list = BuildingElementAttributeList()

attribute_list.add_attribute(1398, "A2") #(1)!
attribute_list.add_attribute(49, "New building") #(2)!

attribute_list.add_attributes_from_parameters(build_ele) #(3)!

attr_set = AllplanBaseElements.AttributeSet(attribute_list.get_attribute_list()) #(4)!
attributes = AllplanBaseElements.Attributes([attr_set])

model_element.SetAttributes(attributes)
  1. The method add_attribute only requires attribute ID and the value and works fine with all attribute value types.
  2. In case of enumeration attribute the method will also work, when passing value to it. Passing a key like add_attribute(49, 0) will also work just fine.
  3. The method add_attributes_from_parameters will add all the attribute parameters from the property palette into the list.
  4. The method get_attribute_list will cast the BuildingElementAttributeList into a python list of Attribute objects so they can be passed to an AttributeSet object.

Appending attributes on ModelElements (2D or 3D) organized in one list of model elements is even simpler, as we can use the set_element_attributes method to do that.

attribute_list = BuildingElementAttributeList()
model_ele_list = ModelEleList()

attribute_list.add_attribute(1398, "A2")
attribute_list.add_attribute(49, "New building")

attribute_list.add_attributes_from_parameters(build_ele)

model_ele_list.set_element_attributes(0, attribute_list.get_attribute_list()) #(1)!
  1. This will append the attributes on the first element in the list. Note, that we don't have to construct the attr_set nor the attributes objects here.

Example on GitHub

For a complete usage of BuildingElementAttributeList and ModelEleList see the example Attributes ( PYP | PY)

Modify attributes of existing elements

Existing model elements can be accessed by a selection. As a result, we become a list of BaseElementAdapter objects, which we describe in detail here. The service class ElementsAttributeService provides methods to read and modify the attributes of adapters and is therefore the best way to manage the attributes of existing model elements.

Getting attributes

The method GetAttributes gets the attributes from an element adapter as a list of tuples with pairs: (attribute id, value).

>>> AllplanBaseElements.ElementsAttributeService.GetAttributes(element_adapter)
[(10, '00011400000000026'), #(1)!
 ...
 (49, "New building"), #(2)!
 ...
 (1398, "A2")] #(1)!
  1. The attribute no. 10 is the Allright_Comp_ID
  2. The attribute Status with its value. Note that Status is an enumeration attribute. In this case we get the enumeration value, not the key.
  3. The attribute Fire risk factor with its value A2

The optional argument readState of the method GetAttributes enables to choose, which attributes should be read. Refer to the documentation of the enumeration class eAttibuteReadState to see, what options are possible.

Tip

Create a dictionary from the returned tuples to access the desired attribute more easily:

>>> attributes_dict = dict(AllplanBaseElements.ElementsAttributeService.GetAttributes(element_adapter))
>>> attributes_dict[1398]
'A2'

Setting attributes

The methods ChangeAttribute and ChangeAttributes provide the possibility to change the value of an element attribute(s) or, if the given attribute is not present in the element, to append it.

To append/modify one specific attribute to element(s), call:

AllplanBaseElements.ElementsAttributeService.ChangeAttribute(1398, 'A1', element_adapters) #(1)!
AllplanBaseElements.ElementsAttributeService.ChangeAttribute(83, 'Foo', element_adapters) #(2)!
  1. Changing the value of the attribute Fire risk factor to A1. Note that the model elements, you are applying attributes to, must be organized into a BaseElementAdapterList.

  2. This will change the value of the attribute Code text to Foo. If the attribute wasn't existing in the element, it will be appended.

To append/change value of multiple attributes, create a list of pairs (attribute id, value):

attr_list = [(1398, 'A2'), 
             (49, 'New building')]

Tip

You can use PythonPart framework to achieve this. Create a BuildingElementAttributeList as described in the previous paragraph and call the get_attributes_list_as_tuples:

attributes = BuildingElementAttributeList()
attributes.add_attribute(1398, "A1")
attributes.add_attribute(49, 'New building')
attributes.add_attributes_from_parameters(build_ele) #(1)!
attr_list = attributes.get_attributes_list_as_tuples()
  1. You can get all the attributes from the property palette parameters and append them to the list with one call.

Now, apply the new attributes to the desired model elements

AllplanBaseElements.ElementsAttributeService.ChangeAttributes(attr_list, element_adapters)

Example on GitHub

See the full implementation in the example ChangeAttributes ( PYP | PY)

Placeholder