I'm trying to delete some Property Sets from multiple objects, but I have yet to find a way to do this properly.
Currently I'm trying the following, but this leaves me with a corrupted ifc file.
ifc = ifcopenshell.open(filepath)
all_elements = ifc.by_type(element_type)
for element in all_elements:
if element.is_a('IfcTypeObject'):
if element.HasPropertySets:
for definition in element.HasPropertySets:
if SOME CONDITION:
ifc.remove(definition)
else:
for relationship in element.IsDefinedBy:
if relationship.is_a('IfcRelDefinesByProperties'):
definition = relationship.RelatingPropertyDefinition
if SOME CONDITION:
ifc.remove(ifc.by_guid(definition.GlobalId))
If I save this ifc file and try to get the psets of elements with ifcopenshell.util.element.get_psets(element), I get multiple empty definitions back ( Like remains of the Psets that I wanted to delete).
In my final Code I want to only delete some Psets (f.e. based on name)
How would I go about cleanly removing complete Psets.
Thank you!
You can use the new API, which still is not finished but is evolving rapidly, and the more users testing it, the more we can make it robust for people to do more with less code!
ifcopenshell.api.run("pset.remove_pset", ifc, product=element, pset=definition)
Thank you for your fast reply, that looks like a much more elegant way of doing it.
Is there an easy way to install a version that supports this new api already, preferably with conda?
@AlexanderNitsch just grab it from github - the api folder is just python. https://github.com/IfcOpenShell/IfcOpenShell/tree/v0.6.0/src/ifcopenshell-python/ifcopenshell/api
Also see https://github.com/IfcOpenShell/IfcOpenShell/issues/1293#issuecomment-806457609 since propertysets are shared between objects you might be deleting the same object multiple times.
Most helpful comment
Also see https://github.com/IfcOpenShell/IfcOpenShell/issues/1293#issuecomment-806457609 since propertysets are shared between objects you might be deleting the same object multiple times.