icon

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 attribute of element [Gelöst]


Hello,
I added a custom attribute called SONA_CODE to a wall: text type

I am trying to retrieve the value of this attribute[[[.]]]
I cannot find this attribute[[[.]]][[[.]]][[[.]]] why?
Many many thx! ??
My code looks like this

print("========== DIAGNOSTIC ATTRIBUTS ==========")
attributes = selected_element[.]GetAttributes(AllplanBase[.]eAttibuteReadState[.]ReadAll)
print(f"Nombre total d'attributs: {len(attributes)}")

sona_found = False
for attr_id, attr_val in attributes:
try:
attr_name = AllplanBase[.]AttributeService[.]GetAttributeName(doc, attr_id)
print(f"ID: {attr_id:

Anhänge (1)

Typ: image/png
17-mal heruntergeladen
Größe: 63,58 KiB

Lösung anzeigen Lösung verbergen

Many Thks!
I've done this :

# Récupérer l'ID de l'attribut SONA_CODE une seule fois
self.sona_attribute_id = AllplanBase.AttributeService.GetAttributeID(
	self.current_doc,
	"SONA_CODE"
)

def get_element_sona_value(self, element: AllplanElementAdapter.BaseElementAdapter) -> str:
        """Récupérer la valeur SONA_CODE d'un élément de manière sécurisée"""
        try:
            if self.sona_attribute_id is None:
                return "(attribut non disponible)"

            # Lire tous les attributs de l'élément
            attributes = AllplanBase.ElementsAttributeService.GetAttributes(
                element,
                AllplanBase.eAttibuteReadState.ReadAllAndComputable
            )

            # Chercher notre attribut SONA_CODE
            for attr_id, attr_value in attributes:
                if attr_id == self.sona_attribute_id:
                    return str(attr_value) if attr_value is not None else "(vide)"

            return "(vide)"

        except Exception as e:
            print(f"⚠️ Erreur lors de la lecture de SONA_CODE: {e}")
            return "(erreur de lecture)"

Hi

I will suppose that in your case you are using a ScriptObject PythonPart.

So, if I do in self.execute() :

attr_test = BaseElements.AttributeService.GetAttributeID(self.document, "TEST_ATTR")
value = next(attr[1] for attr in self.selection_result.sel_element.GetAttributes(BaseElements.eAttibuteReadState.ReadAll) if attr[0] == attr_test)

It's working because I'm working on a wall tier and the attribute is on it

Be careful to the assignment of your attribute (total wall or wall tier) be ok with your selected object

Best regards
Christophe

Anhänge (2)

Typ: image/png
8-mal heruntergeladen
Größe: 9,63 KiB
Typ: image/png
5-mal heruntergeladen
Größe: 2,47 KiB

Many Thks!
I've done this :

# Récupérer l'ID de l'attribut SONA_CODE une seule fois
self.sona_attribute_id = AllplanBase.AttributeService.GetAttributeID(
	self.current_doc,
	"SONA_CODE"
)

def get_element_sona_value(self, element: AllplanElementAdapter.BaseElementAdapter) -> str:
        """Récupérer la valeur SONA_CODE d'un élément de manière sécurisée"""
        try:
            if self.sona_attribute_id is None:
                return "(attribut non disponible)"

            # Lire tous les attributs de l'élément
            attributes = AllplanBase.ElementsAttributeService.GetAttributes(
                element,
                AllplanBase.eAttibuteReadState.ReadAllAndComputable
            )

            # Chercher notre attribut SONA_CODE
            for attr_id, attr_value in attributes:
                if attr_id == self.sona_attribute_id:
                    return str(attr_value) if attr_value is not None else "(vide)"

            return "(vide)"

        except Exception as e:
            print(f"⚠️ Erreur lors de la lecture de SONA_CODE: {e}")
            return "(erreur de lecture)"