Fix error showing material/profile psets in bbim after 691815fd41

This commit is contained in:
Andrej730
2024-09-07 10:47:53 +05:00
parent c1d5c18724
commit e224bfd19f
2 changed files with 23 additions and 5 deletions
@@ -445,11 +445,18 @@ def get_elements_by_pset(pset: ifcopenshell.entity_instance) -> set[ifcopenshell
"""Retrieve the elements (or element types) that are using the provided property set."""
is_ifc2x3 = pset.file.schema == "IFC2X3"
elements = set()
rels = pset.PropertyDefinitionOf if is_ifc2x3 else pset.DefinesOccurrence
for rel in rels:
elements.update(rel.RelatedObjects)
for element_type in pset.DefinesType:
elements.add(element_type)
if pset.is_a("IfcPropertySet"):
rels = pset.PropertyDefinitionOf if is_ifc2x3 else pset.DefinesOccurrence
for rel in rels:
elements.update(rel.RelatedObjects)
for element_type in pset.DefinesType:
elements.add(element_type)
elif pset.is_a("IfcProfileProperties"):
elements.add(pset.ProfileDefinition)
elif pset.is_a("IfcMaterialProperties"):
elements.add(pset.Material)
else:
raise Exception(f"Unexpected pset type: '{pset.is_a()}' ({pset}).")
return elements
@@ -16,6 +16,7 @@
# You should have received a copy of the GNU Lesser General Public License
# along with IfcOpenShell. If not, see <http://www.gnu.org/licenses/>.
import ifcopenshell.api.profile
import pytest
import test.bootstrap
import ifcopenshell.api.void
@@ -268,6 +269,16 @@ class TestGetElementsUsingPset(test.bootstrap.IFC4):
ifcopenshell.api.pset.assign_pset(self.file, [element, element_type], pset)
assert subject.get_elements_by_pset(pset) == {element, element_type}
def test_get_material_for_pset(self):
material = ifcopenshell.api.material.add_material(self.file)
pset = ifcopenshell.api.pset.add_pset(self.file, material, "FooBar")
assert subject.get_elements_by_pset(pset) == {material}
def test_get_profile_for_pset(self):
profile = ifcopenshell.api.profile.add_parameterized_profile(self.file, ifc_class="IfcRectangleProfileDef")
pset = ifcopenshell.api.pset.add_pset(self.file, profile, "FooBar")
assert subject.get_elements_by_pset(pset) == {profile}
class TestGetElementsUsingPsetIFC2X3(test.bootstrap.IFC2X3, TestGetElementsUsingPset): ...