Support Forum

Attach new attribute to building elements [Gelöst]


Hello!
I want to do the following:

  • Retrieve all building elements I could place in my document, like smart parts, walls, doors, etc
    Create an attribute, where the data type and unit can be defined by the user, as well as the name and a description
    Attach the attribute to the elements I have retrieved earlier

Is this something that can be done programmatically? I have not found methods that I could use for this and help would be very much appreciated!

Kind regards
Melanie

Lösung anzeigen Lösung verbergen

Hello Melanie,

as Sander said, it is possible. Have a look on the links he provided.

One important thing: if I understood correctly, you want to create a new attribute definition on the fly, where the user can define (I assume) the attribute's name and the data type stored in it. If that's the case, you can do it (see here, but be aware that in case you are working in a workgroup, only office administrators (or the owner of the current project) will be able to use your PythonPart. This is because adding a new attribute definition can be done only by a user with admin privileges (if the definitions are stored in the office-standard) or by the project owner (if the definitions are project-related).

Assigning an attribute value to an element does not require those privileges, when the attribute definition already exists.

Best,
Bart

Hello Melanie,

That is possible with the Python API. You can check the documention on how to implement this:

How to add User attributes: https://pythonparts.allplan.com/2024/manual/features/attributes/ This page also hints at the examples Allplan provides.

How to apply attributes to existing elements: https://pythonparts.allplan.com/2024/manual/features/attributes/element_attributes/

http://www.cadblanche.eu

Hello Melanie,

as Sander said, it is possible. Have a look on the links he provided.

One important thing: if I understood correctly, you want to create a new attribute definition on the fly, where the user can define (I assume) the attribute's name and the data type stored in it. If that's the case, you can do it (see here, but be aware that in case you are working in a workgroup, only office administrators (or the owner of the current project) will be able to use your PythonPart. This is because adding a new attribute definition can be done only by a user with admin privileges (if the definitions are stored in the office-standard) or by the project owner (if the definitions are project-related).

Assigning an attribute value to an element does not require those privileges, when the attribute definition already exists.

Best,
Bart

Thanks SanderP for the response!
I did see the attribute list, etc, but I did not understand how I could add an attribute, e.g with the name "xyz", unit "m", and description "some description".
Because in the documentation it says for example
attribute_list.add_attribute(1398, "A2")
but what is the id and the string? I guess this is not the id of the attribute itself, because I need to handle a lot of attributes and it would be very unsafe to create all ids by myself
And it seems like the string, in this case "A2" is not the name but the value the attribute has...

Hi,

In this example :

attribute_list.add_attribute(1398, "A2")

1398 is the attribute ID which is : Fire risk factor

"A2" is the value (be careful with the type of data)

Look at the attribute manager for the attributes list (by default in C:\Program Files\Allplan\Allplan\2024\Prg).

edit:

for a better understanding of the code and/or later rereading, I advise adding the name of the attribute as a comment like below

# Trade @209@
attr_list.add_attribute(209, 13)

Christophe

Anhänge (1)

Typ: image/png
40-mal heruntergeladen
Größe: 78,38 KiB

Zitiert von: melanieernst
...
Because in the documentation it says for example

attribute_list.add_attribute(1398, "A2")
...


You have to distinguish between assigning an attribute to an existing object and at an object you are about to create. As I understood, your PythonPart should select all the elements existing in the current document and assign attributes to them. If that's correct, you should have a look on the section Modify attributes of existing elements.

Best,
Bart