mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-08-09 17:31:45 +00:00
Get psets utility can now filter only psets or qtos
This commit is contained in:
@@ -1,16 +1,24 @@
|
||||
import ifcopenshell
|
||||
|
||||
|
||||
def get_psets(element):
|
||||
def get_psets(element, psets_only=False, qtos_only=False):
|
||||
psets = {}
|
||||
if element.is_a("IfcTypeObject"):
|
||||
if element.HasPropertySets:
|
||||
for definition in element.HasPropertySets:
|
||||
if psets_only and not definition.is_a("IfcPropertySet"):
|
||||
continue
|
||||
if qtos_only and not definition.is_a("IfcElementQuantity"):
|
||||
continue
|
||||
psets[definition.Name] = get_property_definition(definition)
|
||||
elif hasattr(element, "IsDefinedBy"):
|
||||
for relationship in element.IsDefinedBy:
|
||||
if relationship.is_a("IfcRelDefinesByProperties"):
|
||||
definition = relationship.RelatingPropertyDefinition
|
||||
if psets_only and not definition.is_a("IfcPropertySet"):
|
||||
continue
|
||||
if qtos_only and not definition.is_a("IfcElementQuantity"):
|
||||
continue
|
||||
psets[definition.Name] = get_property_definition(definition)
|
||||
return psets
|
||||
|
||||
|
||||
@@ -10,36 +10,52 @@ class TestGetPsetsIFC4(test.bootstrap.IFC4):
|
||||
assert subject.get_psets(element) == {}
|
||||
pset = ifcopenshell.api.run("pset.add_pset", self.file, product=element, name="name")
|
||||
ifcopenshell.api.run("pset.edit_pset", self.file, pset=pset, properties={"a": "b"})
|
||||
assert subject.get_psets(element) == {"name": {"a": "b", "id": 2}}
|
||||
assert subject.get_psets(element) == {"name": {"a": "b", "id": pset.id()}}
|
||||
|
||||
def test_getting_the_psets_of_a_product_type_as_a_dictionary(self):
|
||||
type_element = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcWallType")
|
||||
assert subject.get_psets(type_element) == {}
|
||||
pset = ifcopenshell.api.run("pset.add_pset", self.file, product=type_element, name="name")
|
||||
ifcopenshell.api.run("pset.edit_pset", self.file, pset=pset, properties={"x": "y"})
|
||||
assert subject.get_psets(type_element) == {"name": {"x": "y", "id": 2}}
|
||||
assert subject.get_psets(type_element) == {"name": {"x": "y", "id": pset.id()}}
|
||||
|
||||
def test_getting_psets_from_an_element_which_cannot_have_psets(self):
|
||||
assert subject.get_psets(self.file.create_entity("IfcPerson")) == {}
|
||||
|
||||
def test_only_getting_psets_and_not_qtos(self):
|
||||
element = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcWall")
|
||||
pset = ifcopenshell.api.run("pset.add_pset", self.file, product=element, name="pset")
|
||||
ifcopenshell.api.run("pset.edit_pset", self.file, pset=pset, properties={"a": "b"})
|
||||
qto = ifcopenshell.api.run("pset.add_qto", self.file, product=element, name="qto")
|
||||
ifcopenshell.api.run("pset.edit_qto", self.file, qto=qto, properties={"x": 42})
|
||||
assert subject.get_psets(element, psets_only=True) == {"pset": {"a": "b", "id": pset.id()}}
|
||||
|
||||
def test_only_getting_qtos_and_not_psets(self):
|
||||
element = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcWall")
|
||||
pset = ifcopenshell.api.run("pset.add_pset", self.file, product=element, name="pset")
|
||||
ifcopenshell.api.run("pset.edit_pset", self.file, pset=pset, properties={"a": "b"})
|
||||
qto = ifcopenshell.api.run("pset.add_qto", self.file, product=element, name="qto")
|
||||
ifcopenshell.api.run("pset.edit_qto", self.file, qto=qto, properties={"x": 42})
|
||||
assert subject.get_psets(element, qtos_only=True) == {"qto": {"x": 42, "id": qto.id()}}
|
||||
|
||||
|
||||
class TestGetPropertyDefinitionIFC4(test.bootstrap.IFC4):
|
||||
def test_getting_the_properties_of_a_pset(self):
|
||||
element = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcWall")
|
||||
pset = ifcopenshell.api.run("pset.add_pset", self.file, product=element, name="name")
|
||||
ifcopenshell.api.run("pset.edit_pset", self.file, pset=pset, properties={"a": "b"})
|
||||
assert subject.get_property_definition(pset) == {"a": "b", "id": 2}
|
||||
assert subject.get_property_definition(pset) == {"a": "b", "id": pset.id()}
|
||||
|
||||
def test_getting_the_properties_of_a_qto(self):
|
||||
element = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcWall")
|
||||
qto = ifcopenshell.api.run("pset.add_qto", self.file, product=element, name="name")
|
||||
ifcopenshell.api.run("pset.edit_qto", self.file, qto=qto, properties={"x": 42})
|
||||
assert subject.get_property_definition(qto) == {"x": 42, "id": 2}
|
||||
assert subject.get_property_definition(qto) == {"x": 42, "id": qto.id()}
|
||||
|
||||
def test_getting_the_properties_of_a_predefined_pset(self):
|
||||
pset = self.file.create_entity("IfcDoorLiningProperties", ifcopenshell.guid.new())
|
||||
pset.LiningDepth = 42
|
||||
assert subject.get_property_definition(pset) == {"LiningDepth": 42, "id": 1}
|
||||
assert subject.get_property_definition(pset) == {"LiningDepth": 42, "id": pset.id()}
|
||||
|
||||
|
||||
class TestGetQuantitiesIFC4(test.bootstrap.IFC4):
|
||||
|
||||
Reference in New Issue
Block a user