Clean up orphaned meshes

- delete_ifc_project
- bim.add_constr_type_instance
- adding transitions and bends
- add profile / slab / wall
This commit is contained in:
Andrej730
2023-09-18 10:35:47 +05:00
parent 8e375dcf73
commit d67eae55df
7 changed files with 25 additions and 0 deletions
@@ -847,6 +847,7 @@ class MEPAddTransition(bpy.types.Operator, tool.Ifc.Operator):
)
body = ifcopenshell.util.representation.get_context(ifc_file, "Model", "Body", "MODEL_VIEW")
tool.Model.replace_object_ifc_representation(body, obj, rep)
tool.Blender.remove_data_block(mesh)
pset = ifcopenshell.api.run("pset.add_pset", tool.Ifc.get(), product=transition_type, name="BBIM_Fitting")
ifcopenshell.api.run(
"pset.edit_pset",
@@ -1188,6 +1189,7 @@ class MEPAddBend(bpy.types.Operator, tool.Ifc.Operator):
)
body = ifcopenshell.util.representation.get_context(ifc_file, "Model", "Body", "MODEL_VIEW")
tool.Model.replace_object_ifc_representation(body, obj, rep)
tool.Blender.remove_data_block(mesh)
pset = ifcopenshell.api.run("pset.add_pset", tool.Ifc.get(), product=bend_type, name="BBIM_Fitting")
ifcopenshell.api.run(
"pset.edit_pset",
@@ -185,8 +185,13 @@ class AddConstrTypeInstance(bpy.types.Operator):
collection_obj = collection.BIMCollectionProperties.obj
bpy.ops.bim.assign_class(obj=obj.name, ifc_class=instance_class)
tool.Blender.remove_data_block(mesh) # Remove "Instance" mesh
mesh_data = obj.data
element = tool.Ifc.get_entity(obj)
blenderbim.core.type.assign_type(tool.Ifc, tool.Type, element=element, type=relating_type)
if obj.data != mesh_data: # remove orphaned mesh from "bim.assign_class"
tool.Blender.remove_data_block(mesh_data)
# Update required as core.type.assign_type may change obj.data
# TODO: This is inefficient. It literally creates a mesh, then potentially removes it.
@@ -132,6 +132,7 @@ class DumbProfileGenerator:
is_global=True,
should_sync_changes_first=False,
)
tool.Blender.remove_data_block(mesh)
pset = ifcopenshell.api.run("pset.add_pset", self.file, product=element, name="EPset_Parametric")
ifcopenshell.api.run("pset.edit_pset", self.file, pset=pset, properties={"Engine": "BlenderBIM.DumbProfile"})
@@ -196,6 +196,7 @@ class DumbSlabGenerator:
is_global=True,
should_sync_changes_first=False,
)
tool.Blender.remove_data_block(mesh)
if self.footprint_context:
extrusion = tool.Model.get_extrusion(representation)
@@ -637,6 +637,7 @@ class DumbWallGenerator:
is_global=True,
should_sync_changes_first=False,
)
tool.Blender.remove_data_block(mesh)
pset = ifcopenshell.api.run("pset.add_pset", self.file, product=element, name="EPset_Parametric")
ifcopenshell.api.run("pset.edit_pset", self.file, pset=pset, properties={"Engine": "BlenderBIM.DumbLayer2"})
obj.select_set(True)
@@ -115,6 +115,12 @@ class Geometry(blenderbim.core.tool.Geometry):
for port in ifcopenshell.util.system.get_ports(element):
blenderbim.core.system.remove_port(tool.Ifc, tool.System, port=port)
ifcopenshell.api.run("root.remove_product", tool.Ifc.get(), product=element)
if isinstance(obj.data, bpy.types.Mesh) and not tool.Ifc.get_entity_by_id(
obj.data.BIMMeshProperties.ifc_definition_id
):
tool.Blender.remove_data_block(obj.data)
if is_spatial:
blenderbim.core.spatial.load_container_manager(tool.Spatial)
try:
+9
View File
@@ -86,6 +86,15 @@ class Ifc(blenderbim.core.tool.Ifc):
except:
pass
@classmethod
def get_entity_by_id(cls, entity_id):
"""useful to check whether entity_id is still exists in IFC"""
ifc_file = tool.Ifc.get()
try:
return ifc_file.by_id(entity_id)
except RuntimeError:
return None
@classmethod
def get_object(cls, element):
return IfcStore.get_element(element.id())