mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-08-09 09:21:46 +00:00
Remove orphaned IfcPropertyEnumeration
Noticed a couple hundreds of orphaned IfcPropertyEnumeration in my .ifc like below 😁
IFCPROPERTYENUMERATION('Status',(IFCLABEL('NEW'),IFCLABEL('EXISTING'),IFCLABEL('DEMOLISH'),IFCLABEL('TEMPORARY'),IFCLABEL('OTHER'),IFCLABEL('NOTKNOWN'),IFCLABEL('UNSET')),$);
This commit is contained in:
@@ -65,8 +65,13 @@ class Usecase:
|
|||||||
elif self.settings["pset"].is_a() in ("IfcMaterialProperties", "IfcProfileProperties"):
|
elif self.settings["pset"].is_a() in ("IfcMaterialProperties", "IfcProfileProperties"):
|
||||||
properties = self.settings["pset"].Properties or []
|
properties = self.settings["pset"].Properties or []
|
||||||
for prop in properties:
|
for prop in properties:
|
||||||
if self.file.get_total_inverses(prop) == 1:
|
if self.file.get_total_inverses(prop) != 1:
|
||||||
self.file.remove(prop)
|
continue
|
||||||
|
if prop.is_a("IfcPropertyEnumeratedValue"):
|
||||||
|
enumeration = prop.EnumerationReference
|
||||||
|
if self.file.get_total_inverses(enumeration) == 1:
|
||||||
|
self.file.remove(enumeration)
|
||||||
|
self.file.remove(prop)
|
||||||
self.file.remove(self.settings["pset"])
|
self.file.remove(self.settings["pset"])
|
||||||
for element in to_purge:
|
for element in to_purge:
|
||||||
self.file.remove(element)
|
self.file.remove(element)
|
||||||
|
|||||||
@@ -83,3 +83,27 @@ class TestRemovePset(test.bootstrap.IFC4):
|
|||||||
pset2.HasProperties = pset.HasProperties
|
pset2.HasProperties = pset.HasProperties
|
||||||
ifcopenshell.api.run("pset.remove_pset", self.file, product=element, pset=pset)
|
ifcopenshell.api.run("pset.remove_pset", self.file, product=element, pset=pset)
|
||||||
assert pset2.HasProperties
|
assert pset2.HasProperties
|
||||||
|
|
||||||
|
def test_removing_a_pset_with_enumeration(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_WallCommon")
|
||||||
|
ifcopenshell.api.run("pset.edit_pset", self.file, pset=pset, properties={"Status": ["NEW"]})
|
||||||
|
ifcopenshell.api.run("pset.remove_pset", self.file, product=element, pset=pset)
|
||||||
|
assert len(self.file.by_type("IfcPropertyEnumeration")) == 0
|
||||||
|
|
||||||
|
def test_removing_a_pset_with_shared_enumeration(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_WallCommon")
|
||||||
|
ifcopenshell.api.run("pset.edit_pset", self.file, pset=pset, properties={"Status": ["NEW"]})
|
||||||
|
|
||||||
|
element2 = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcWall")
|
||||||
|
pset2 = ifcopenshell.api.run("pset.add_pset", self.file, product=element2, name="Pset_WallCommon")
|
||||||
|
ifcopenshell.api.run("pset.edit_pset", self.file, pset=pset2, properties={"Status": ["NEW"]})
|
||||||
|
|
||||||
|
enumeration1 = pset.HasProperties[0].EnumerationReference
|
||||||
|
enumeration2 = pset2.HasProperties[0].EnumerationReference
|
||||||
|
pset2.HasProperties[0].EnumerationReference = enumeration1
|
||||||
|
self.file.remove(enumeration2)
|
||||||
|
|
||||||
|
ifcopenshell.api.run("pset.remove_pset", self.file, product=element, pset=pset)
|
||||||
|
assert len(self.file.by_type("IfcPropertyEnumeration")) == 1
|
||||||
|
|||||||
Reference in New Issue
Block a user