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.
This commit is contained in:
Andrej730
2024-11-06 16:03:44 +05:00
parent e70bc04915
commit 36bd89bb40
2 changed files with 4 additions and 4 deletions
@@ -27,7 +27,7 @@ def get_references(element: ifcopenshell.entity_instance, should_inherit=True) -
references := getattr(element, "HasExternalReference", None) references := getattr(element, "HasExternalReference", None)
) is not None: ) is not None:
return {r.RelatingReference for r in references} 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) element_type = ifcopenshell.util.element.get_type(element)
if element_type and element_type != element: if element_type and element_type != element:
results = get_references(element_type) results = get_references(element_type)
@@ -500,7 +500,7 @@ def get_type(element: ifcopenshell.entity_instance) -> Union[ifcopenshell.entity
Note: `get_type(type_element) == type_element`. Note: `get_type(type_element) == type_element`.
:param element: The element occurrence :param element: The element occurrence (IfcObject)
:type: ifcopenshell.entity_instance :type: ifcopenshell.entity_instance
:return: The related type element :return: The related type element
:rtype: Union[ifcopenshell.entity_instance, None] :rtype: Union[ifcopenshell.entity_instance, None]
@@ -517,11 +517,11 @@ def get_type(element: ifcopenshell.entity_instance) -> Union[ifcopenshell.entity
schema = element.file.schema schema = element.file.schema
if schema != "IFC2X3": if schema != "IFC2X3":
if is_typed_by := getattr(element, "IsTypedBy", []): if is_typed_by := getattr(element, "IsTypedBy", ()):
return is_typed_by[0].RelatingType return is_typed_by[0].RelatingType
return return
if is_defined_by := element.IsDefinedBy: # IFC2X3 if is_defined_by := getattr(element, "IsDefinedBy", ()): # IFC2X3
for relationship in is_defined_by: for relationship in is_defined_by:
if relationship.is_a("IfcRelDefinesByType"): if relationship.is_a("IfcRelDefinesByType"):
return relationship.RelatingType return relationship.RelatingType