From 36bd89bb40b63e8a0c5e3ecbdfcacf6996fc82cb Mon Sep 17 00:00:00 2001 From: Andrej730 Date: Wed, 6 Nov 2024 16:03:44 +0500 Subject: [PATCH] ifcopenshell.util.element.get_type to be less strict again after d443c5e I guess by accident in d443c5e I've made this method too strict and it broke get_references using it for IfcPropertySets. Maybe it's a good idea to make it more strict in the future, for now just restoring the previous behaviour. --- src/ifcopenshell-python/ifcopenshell/util/classification.py | 2 +- src/ifcopenshell-python/ifcopenshell/util/element.py | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/ifcopenshell-python/ifcopenshell/util/classification.py b/src/ifcopenshell-python/ifcopenshell/util/classification.py index 5d095a4052..a372dd7046 100644 --- a/src/ifcopenshell-python/ifcopenshell/util/classification.py +++ b/src/ifcopenshell-python/ifcopenshell/util/classification.py @@ -27,7 +27,7 @@ def get_references(element: ifcopenshell.entity_instance, should_inherit=True) - references := getattr(element, "HasExternalReference", None) ) is not None: return {r.RelatingReference for r in references} - if should_inherit: + if should_inherit and element.is_a("IfcObject"): element_type = ifcopenshell.util.element.get_type(element) if element_type and element_type != element: results = get_references(element_type) diff --git a/src/ifcopenshell-python/ifcopenshell/util/element.py b/src/ifcopenshell-python/ifcopenshell/util/element.py index 670c8a9953..95c1031ae1 100644 --- a/src/ifcopenshell-python/ifcopenshell/util/element.py +++ b/src/ifcopenshell-python/ifcopenshell/util/element.py @@ -500,7 +500,7 @@ def get_type(element: ifcopenshell.entity_instance) -> Union[ifcopenshell.entity Note: `get_type(type_element) == type_element`. - :param element: The element occurrence + :param element: The element occurrence (IfcObject) :type: ifcopenshell.entity_instance :return: The related type element :rtype: Union[ifcopenshell.entity_instance, None] @@ -517,11 +517,11 @@ def get_type(element: ifcopenshell.entity_instance) -> Union[ifcopenshell.entity schema = element.file.schema if schema != "IFC2X3": - if is_typed_by := getattr(element, "IsTypedBy", []): + if is_typed_by := getattr(element, "IsTypedBy", ()): return is_typed_by[0].RelatingType return - if is_defined_by := element.IsDefinedBy: # IFC2X3 + if is_defined_by := getattr(element, "IsDefinedBy", ()): # IFC2X3 for relationship in is_defined_by: if relationship.is_a("IfcRelDefinesByType"): return relationship.RelatingType