From 5c4046e05470855a65d05aa5a4b6080a99d7a7a2 Mon Sep 17 00:00:00 2001 From: Thomas Krijnen Date: Thu, 15 Jan 2026 16:11:58 +0100 Subject: [PATCH] declaration as property --- .../ifcopenshell/api/project/append_asset.py | 2 +- .../ifcopenshell/api/style/edit_surface_style.py | 2 +- src/ifcopenshell-python/ifcopenshell/util/schema.py | 4 ++-- src/ifcopenshell-python/ifcopenshell/util/selector.py | 6 +++--- src/ifcopenshell-python/ifcopenshell/util/unit.py | 2 +- 5 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/ifcopenshell-python/ifcopenshell/api/project/append_asset.py b/src/ifcopenshell-python/ifcopenshell/api/project/append_asset.py index bd96bf7135..9051adb821 100644 --- a/src/ifcopenshell-python/ifcopenshell/api/project/append_asset.py +++ b/src/ifcopenshell-python/ifcopenshell/api/project/append_asset.py @@ -615,7 +615,7 @@ class Usecase: nonlocal attributes_ if attributes_ is not None: return attributes_ - attributes_ = element.declaration().as_entity().all_attributes() + attributes_ = element.declaration.all_attributes() return attributes_ def get_existing_element_( diff --git a/src/ifcopenshell-python/ifcopenshell/api/style/edit_surface_style.py b/src/ifcopenshell-python/ifcopenshell/api/style/edit_surface_style.py index 7438230ee0..5103f604f8 100644 --- a/src/ifcopenshell-python/ifcopenshell/api/style/edit_surface_style.py +++ b/src/ifcopenshell-python/ifcopenshell/api/style/edit_surface_style.py @@ -81,7 +81,7 @@ class Usecase: self.style = style attribute_types: dict[str, str] = {} - for attribute in style.declaration().as_entity().all_attributes(): + for attribute in style.declaration.all_attributes(): attribute_type = attribute.type_of_attribute() if attribute_type.as_aggregation_type() is None: attribute_type = attribute_type.declared_type().name() diff --git a/src/ifcopenshell-python/ifcopenshell/util/schema.py b/src/ifcopenshell-python/ifcopenshell/util/schema.py index 02ee72bd72..e3e9ad7540 100644 --- a/src/ifcopenshell-python/ifcopenshell/util/schema.py +++ b/src/ifcopenshell-python/ifcopenshell/util/schema.py @@ -70,7 +70,7 @@ def get_declaration(element: ifcopenshell.entity_instance): print(declaration.is_abstract()) # False print(declaration.supertype().name()) # IfcBuildingElement """ - return element.declaration().as_entity() + return element.declaration def is_a(declaration: ifcopenshell.ifcopenshell_wrapper.declaration, ifc_class: str) -> bool: @@ -104,7 +104,7 @@ def get_supertypes( .. code:: python wall = model.createIfcWall() - results = ifcopenshell.util.schema.get_supertypes(wall.declaration().as_entity()) + results = ifcopenshell.util.schema.get_supertypes(wall.declaration.as_entity()) # [, , ..., ] """ results = [] diff --git a/src/ifcopenshell-python/ifcopenshell/util/selector.py b/src/ifcopenshell-python/ifcopenshell/util/selector.py index e6b662a9b3..4d05912eb8 100644 --- a/src/ifcopenshell-python/ifcopenshell/util/selector.py +++ b/src/ifcopenshell-python/ifcopenshell/util/selector.py @@ -569,8 +569,8 @@ def set_element_value( element: ifcopenshell.entity_instance, value: Union[str, None], *, is_type: bool ) -> None: predefined_type = element.PredefinedType - declaration = element.declaration() - entity = declaration.as_entity() + declaration = element.declaration + entity = declaration enum_attr = next(attr for attr in entity.attributes() if attr.name() == "PredefinedType") enum_items = ifcopenshell.util.attribute.get_enum_items(enum_attr) @@ -639,7 +639,7 @@ def set_element_value( except: # Try to cast data_type = ifcopenshell.util.attribute.get_primitive_type( - element.declaration().as_entity().attribute_by_index(element.get_argument_index(key)) + element.declaration.attribute_by_index(element.get_argument_index(key)) ) if data_type == "string": value = str(value) diff --git a/src/ifcopenshell-python/ifcopenshell/util/unit.py b/src/ifcopenshell-python/ifcopenshell/util/unit.py index 850b609846..c45d226128 100644 --- a/src/ifcopenshell-python/ifcopenshell/util/unit.py +++ b/src/ifcopenshell-python/ifcopenshell/util/unit.py @@ -475,7 +475,7 @@ def get_property_unit( measure_class = None if prop.is_a("IfcPhysicalSimpleQuantity"): - entity = prop.declaration().as_entity() + entity = prop.declaration measure_class = entity.attribute_by_index(3).type_of_attribute().declared_type().name() elif prop.is_a("IfcPropertySingleValue"): measure_class = prop.NominalValue.is_a()