mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-09-07 12:56:26 +00:00
Fix error showing material/profile psets in bbim after 691815fd41
This commit is contained in:
@@ -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."""
|
"""Retrieve the elements (or element types) that are using the provided property set."""
|
||||||
is_ifc2x3 = pset.file.schema == "IFC2X3"
|
is_ifc2x3 = pset.file.schema == "IFC2X3"
|
||||||
elements = set()
|
elements = set()
|
||||||
rels = pset.PropertyDefinitionOf if is_ifc2x3 else pset.DefinesOccurrence
|
if pset.is_a("IfcPropertySet"):
|
||||||
for rel in rels:
|
rels = pset.PropertyDefinitionOf if is_ifc2x3 else pset.DefinesOccurrence
|
||||||
elements.update(rel.RelatedObjects)
|
for rel in rels:
|
||||||
for element_type in pset.DefinesType:
|
elements.update(rel.RelatedObjects)
|
||||||
elements.add(element_type)
|
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
|
return elements
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -16,6 +16,7 @@
|
|||||||
# You should have received a copy of the GNU Lesser General Public License
|
# You should have received a copy of the GNU Lesser General Public License
|
||||||
# along with IfcOpenShell. If not, see <http://www.gnu.org/licenses/>.
|
# along with IfcOpenShell. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
import ifcopenshell.api.profile
|
||||||
import pytest
|
import pytest
|
||||||
import test.bootstrap
|
import test.bootstrap
|
||||||
import ifcopenshell.api.void
|
import ifcopenshell.api.void
|
||||||
@@ -268,6 +269,16 @@ class TestGetElementsUsingPset(test.bootstrap.IFC4):
|
|||||||
ifcopenshell.api.pset.assign_pset(self.file, [element, element_type], pset)
|
ifcopenshell.api.pset.assign_pset(self.file, [element, element_type], pset)
|
||||||
assert subject.get_elements_by_pset(pset) == {element, element_type}
|
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): ...
|
class TestGetElementsUsingPsetIFC2X3(test.bootstrap.IFC2X3, TestGetElementsUsingPset): ...
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user