Removing with ifcopenshell.util.element.remove_deep2
edited May 17 in General
I'm trying to remove..
#259822=IFCPRODUCTDEFINITIONSHAPE($,$,(#259820,#259821)); and everything it's attached to,
from the attached file, since it doesn't seem to be attached to an IfcElement or type.
I'm using the following, but it doesn't remove the associated IFCINDEXEDPOLYGONALFACE and IFCPOLYGONALFACESET.
Any clues on how to remove even deeper? :)
import bpy import ifcopenshell import blenderbim.bim.import_ifc from blenderbim.bim.ifc import IfcStore import ifcopenshell.util.element ifc_file = ifcopenshell.open(IfcStore.path) for product_definition_shape in ifc_file.by_type("IfcProductDefinitionShape"): if len(product_definition_shape.ShapeOfProduct) == 0: print(product_definition_shape) ifcopenshell.util.element.remove_deep2(ifc_file, product_definition_shape) ifc_file.write("C:/Users/Owner/Desktop/testy/testymod.ifc")
I wrote two scripts that worked for this file, maybe they are useful for others. Any comments on how to improve them are welcome.
This script looks for orphaned "IfcProductDefinitionShape", deletes them and its representations:
This one looks for orphaned "IfcShapeRepresentation" and deletes them:
so fresh and so clean. https://gitlab.com/openingdesign/mineral_point_residence/-/commit/1c5bbb4a528fc05c8b483ac03c0da6ca4e2654f5
Used the following as well.
Will delete an entity's graph based on element_id
Thank you for the snippets ! How would one batch remove IfcElementTypes with 0 associated instances ?
Good question. Related: https://community.osarch.org/discussion/comment/15386/#Comment_15386
@Gorgious something like:
@Moult Thank you ! How would I remove profiles which are not used in the file ? I've had a bug when creating a profile and one of my profiles got duplicated many times in the profile editor in the scene properties.
AFAIK it's not possible with this interface to know which profiles are used by a IfcMaterialProfileSetUsage, and profile names are not uniquely defined so I don't know which profile I want to keep and which ones I want to remove.
Ah you're right, we don't expose the number of users of the profile in the UI. It would be nice to do so, in
module/profile/operator.pyyou can do
tool.Ifc.get().get_total_inverses(profile)to get the number of users (I think that should be OK for now), and anything with a 0 you can safely delete (either run the operator, or if you want more speed run
ifcopenshell.api.run("profile.remove_profile", tool.Ifc.get(), profile=tool.Ifc.get().by_id(self.profile))directly to avoid UI refreshes).
PR very welcome to add a button to purge unused :)