Das Wissen aller Anwender nutzen

Im Allplan Connect Forum tauschen sich Anwender aus, geben wertvolle Tipps oder beraten sich bei ganz konkreten Aufgabenstellungen − auch international.
Und damit wirklich keine Frage unbeantwortet bleibt, unterstützen die Mitarbeiter des Technischen Supports ebenfalls aktiv das Forum.

Es erwarten Sie:

  • Foren-Vielfalt aus CAD Architektur, CAD Ingenieurbau uvm.
  • Tipps von User für User
  • international: Deutsch, Englisch, Italienisch, Französisch und Tschechisch

Melden Sie sich jetzt an und diskutieren Sie mit!

Zur Registrierung

Get user attributes list with API [Gelöst]

Schlagworte:
  • Allplan
  • 2025
  • WIP
  • 6

Hello,

I want to do the following:

Retrieve all attributes that created by user in a project ("AttributeDefinitionCollectionLocal.xml" from xml folder in .prj project)

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
Tuan Anh

Lösung anzeigen Lösung verbergen

Hi Tuanh,

in the ALLPLAN Python API , there is no differentiation between ALLPLAN native attributes and user-defined attributes. If you for some reason need only the user-defined attribute IDs, you can simply read them from the .xml:

from pathlib import Path
import xml.etree.ElementTree as ET

def get_user_defined_attributes() -> list[int]:
    prj_path = Path(AllplanSettings.AllplanPaths.GetCurPrjPath())
    attribute_definitions = prj_path / Path("Xml\AttributeDefinitionCollectionLocal.xml")
    tree = ET.parse(attribute_definitions)
    root = tree.getroot()
    return [int(attribute.find('Ifnr').text) for attribute in root.findall('AttributeDefinition')]

This function will return you the IDs of all user-defined attributes defined in a project. But note, that attributes can also be defined for the whole office (in std/xml/AttributeDefinitionCollectionLocal.xml). It depends on a project, whether it has its own definitions or not.

When you have the ID of an Attribute, you can use the AttributeService to get its name, value type, default values or any other kind of data.

Maybe you can explain more, why you need this differentiation?

I hope that helps!

Best,
Bart

Hi Tuanh,

in the ALLPLAN Python API , there is no differentiation between ALLPLAN native attributes and user-defined attributes. If you for some reason need only the user-defined attribute IDs, you can simply read them from the .xml:

from pathlib import Path
import xml.etree.ElementTree as ET

def get_user_defined_attributes() -> list[int]:
    prj_path = Path(AllplanSettings.AllplanPaths.GetCurPrjPath())
    attribute_definitions = prj_path / Path("Xml\AttributeDefinitionCollectionLocal.xml")
    tree = ET.parse(attribute_definitions)
    root = tree.getroot()
    return [int(attribute.find('Ifnr').text) for attribute in root.findall('AttributeDefinition')]

This function will return you the IDs of all user-defined attributes defined in a project. But note, that attributes can also be defined for the whole office (in std/xml/AttributeDefinitionCollectionLocal.xml). It depends on a project, whether it has its own definitions or not.

When you have the ID of an Attribute, you can use the AttributeService to get its name, value type, default values or any other kind of data.

Maybe you can explain more, why you need this differentiation?

I hope that helps!

Best,
Bart