mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-08-09 09:21:46 +00:00
Bonsai - purge unused IfcApplications and IfcOrganizations
This commit is contained in:
@@ -42,7 +42,7 @@ from bpy_extras.io_utils import ImportHelper, ExportHelper
|
|||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
from bonsai import get_debug_info, format_debug_info
|
from bonsai import get_debug_info, format_debug_info
|
||||||
from bonsai.bim.ifc import IfcStore
|
from bonsai.bim.ifc import IfcStore
|
||||||
from typing import get_args, Union, Any, TYPE_CHECKING, Literal, get_args
|
from typing import get_args, Union, Any, TYPE_CHECKING, Literal, get_args, assert_never
|
||||||
|
|
||||||
if TYPE_CHECKING:
|
if TYPE_CHECKING:
|
||||||
from bonsai.bim.prop import Attribute
|
from bonsai.bim.prop import Attribute
|
||||||
@@ -747,16 +747,14 @@ class PurgeUnusedObjects(bpy.types.Operator, tool.Ifc.Operator):
|
|||||||
bl_label = "Purge Unused Objects"
|
bl_label = "Purge Unused Objects"
|
||||||
bl_options = {"REGISTER", "UNDO"}
|
bl_options = {"REGISTER", "UNDO"}
|
||||||
|
|
||||||
object_type: bpy.props.EnumProperty(
|
object_type: bpy.props.EnumProperty( # pyright: ignore[reportRedeclaration]
|
||||||
name="Object Type",
|
name="Object Type",
|
||||||
items=(
|
items=((s, s.capitalize(), "") for s in get_args(PurgeObjectType)),
|
||||||
("TYPE", "Type", ""),
|
|
||||||
("PROFILE", "Profile", ""),
|
|
||||||
("STYLE", "Style", ""),
|
|
||||||
("MATERIAL", "Material", ""),
|
|
||||||
),
|
|
||||||
)
|
)
|
||||||
|
|
||||||
|
if TYPE_CHECKING:
|
||||||
|
object_type: PurgeObjectType
|
||||||
|
|
||||||
def _execute(self, context):
|
def _execute(self, context):
|
||||||
object_type = self.object_type
|
object_type = self.object_type
|
||||||
if object_type == "TYPE":
|
if object_type == "TYPE":
|
||||||
@@ -767,9 +765,10 @@ class PurgeUnusedObjects(bpy.types.Operator, tool.Ifc.Operator):
|
|||||||
purged = tool.Style.purge_unused_styles()
|
purged = tool.Style.purge_unused_styles()
|
||||||
elif object_type == "MATERIAL":
|
elif object_type == "MATERIAL":
|
||||||
purged = tool.Material.purge_unused_materials()
|
purged = tool.Material.purge_unused_materials()
|
||||||
|
elif object_type in ("APPLICATION", "ORGANIZATION"):
|
||||||
|
purged = core.purge_unused_elements(tool.Ifc, tool.Debug, "IfcApplication")
|
||||||
else:
|
else:
|
||||||
self.report({"ERROR"}, f"Invalid object type {object_type}.")
|
assert_never(object_type)
|
||||||
return {"CANCELLED"}
|
|
||||||
|
|
||||||
self.report({"INFO"}, f"{purged} unused {object_type.lower()}s were purged.")
|
self.report({"INFO"}, f"{purged} unused {object_type.lower()}s were purged.")
|
||||||
|
|
||||||
@@ -788,6 +787,10 @@ class PurgeUnusedObjects(bpy.types.Operator, tool.Ifc.Operator):
|
|||||||
props = tool.Material.get_material_props()
|
props = tool.Material.get_material_props()
|
||||||
if props.is_editing:
|
if props.is_editing:
|
||||||
bpy.ops.bim.load_materials()
|
bpy.ops.bim.load_materials()
|
||||||
|
elif object_type == "ORGANIZATION":
|
||||||
|
props = tool.Owner.get_owner_props()
|
||||||
|
if tool.Ifc.get_entity_by_id(props.active_organisation_id) is None:
|
||||||
|
props.active_organisation_id = 0
|
||||||
|
|
||||||
|
|
||||||
class MergeIdenticalObjects(bpy.types.Operator, tool.Ifc.Operator):
|
class MergeIdenticalObjects(bpy.types.Operator, tool.Ifc.Operator):
|
||||||
|
|||||||
@@ -648,8 +648,10 @@ class BIM_PT_purge(Panel):
|
|||||||
|
|
||||||
row = layout.row(align=True)
|
row = layout.row(align=True)
|
||||||
row.label(text="Organizations: ")
|
row.label(text="Organizations: ")
|
||||||
|
row.operator("bim.purge_unused_objects", text="Purge Unused").object_type = "ORGANIZATION"
|
||||||
row.operator("bim.merge_identical_objects", text="Merge Identical").object_type = "ORGANIZATION"
|
row.operator("bim.merge_identical_objects", text="Merge Identical").object_type = "ORGANIZATION"
|
||||||
|
|
||||||
row = layout.row(align=True)
|
row = layout.row(align=True)
|
||||||
row.label(text="Applications: ")
|
row.label(text="Applications: ")
|
||||||
row.operator("bim.merge_identical_objects", text="Merge Identical").object_type = "APPLICATION"
|
row.operator("bim.merge_identical_objects", text="Merge Identical").object_type = "APPLICATION"
|
||||||
|
row.operator("bim.merge_identical_objects", text="Merge Identical").object_type = "APPLICATION"
|
||||||
|
|||||||
@@ -38,5 +38,9 @@ def purge_unused_elements(ifc: type[tool.Ifc], debug: type[tool.Debug], ifc_clas
|
|||||||
ifc_file = ifc.get()
|
ifc_file = ifc.get()
|
||||||
unused_elements = [i for i in ifc_file.by_type(ifc_class) if ifc_file.get_total_inverses(i) == 0]
|
unused_elements = [i for i in ifc_file.by_type(ifc_class) if ifc_file.get_total_inverses(i) == 0]
|
||||||
unused_elements_amount = len(unused_elements)
|
unused_elements_amount = len(unused_elements)
|
||||||
debug.remove_unused_elements(unused_elements)
|
if ifc_class == "IfcApplication":
|
||||||
|
for element in unused_elements:
|
||||||
|
ifc.run("owner.remove_application", application=element)
|
||||||
|
else:
|
||||||
|
debug.remove_unused_elements(unused_elements)
|
||||||
return unused_elements_amount
|
return unused_elements_amount
|
||||||
|
|||||||
Reference in New Issue
Block a user