From ee7cf918ea131e7f5e9276ea1cbb411efd856cd6 Mon Sep 17 00:00:00 2001 From: Andrej730 Date: Wed, 10 Apr 2024 15:22:22 +0500 Subject: [PATCH] get_pset() fix bug getting inherited psets with psets_only/qtos_only = True --- src/ifcopenshell-python/ifcopenshell/util/element.py | 12 +++++++----- src/ifcopenshell-python/test/util/test_element.py | 4 ++++ 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/src/ifcopenshell-python/ifcopenshell/util/element.py b/src/ifcopenshell-python/ifcopenshell/util/element.py index c5af585cec..3cfe75021b 100644 --- a/src/ifcopenshell-python/ifcopenshell/util/element.py +++ b/src/ifcopenshell-python/ifcopenshell/util/element.py @@ -94,11 +94,13 @@ def get_pset( elif qtos_only and not pset.is_a("IfcElementQuantity"): pset = None - if type_pset is not None: - if psets_only and not type_pset.is_a("IfcPropertySet"): - type_pset = None - elif qtos_only and not type_pset.is_a("IfcElementQuantity"): - type_pset = None + if type_pset is not None and not prop: + if psets_only or qtos_only: + type_pset_element = element.file.by_id(type_pset["id"]) + if psets_only and not type_pset_element.is_a("IfcPropertySet"): + type_pset = None + elif qtos_only and not type_pset_element.is_a("IfcElementQuantity"): + type_pset = None if pset is None and type_pset is None: return diff --git a/src/ifcopenshell-python/test/util/test_element.py b/src/ifcopenshell-python/test/util/test_element.py index 7d938eb2bc..2e917e1258 100644 --- a/src/ifcopenshell-python/test/util/test_element.py +++ b/src/ifcopenshell-python/test/util/test_element.py @@ -72,6 +72,10 @@ class TestGetPsetIFC4(test.bootstrap.IFC4): ifcopenshell.api.run("pset.edit_pset", self.file, pset=pset, properties={"z": False}) assert subject.get_pset(element, "name2", "z") is False + # test filters with inherited psets + assert subject.get_pset(element, "name", psets_only=True) == result + assert subject.get_pset(element, "name", qtos_only=True) == None + def test_excluding_inherited_psets(self): element = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcWall") type_element = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcWallType")