From aceb2140ad3409a1f9fb94ed799d8b31299905dd Mon Sep 17 00:00:00 2001 From: Dion Moult Date: Tue, 9 Mar 2021 12:50:50 +1100 Subject: [PATCH] Fix #1361. You can now unlink objects and styles of elements that you've lost the IFC of to recover them. --- .../blenderbim/bim/module/root/operator.py | 2 ++ .../blenderbim/bim/module/root/ui.py | 9 +++++++-- .../blenderbim/bim/module/style/__init__.py | 1 + .../blenderbim/bim/module/style/operator.py | 16 ++++++++++++++-- .../blenderbim/bim/module/style/ui.py | 4 +++- 5 files changed, 27 insertions(+), 5 deletions(-) diff --git a/src/ifcblenderexport/blenderbim/bim/module/root/operator.py b/src/ifcblenderexport/blenderbim/bim/module/root/operator.py index 7eda7f3a96..299ed6aeaf 100644 --- a/src/ifcblenderexport/blenderbim/bim/module/root/operator.py +++ b/src/ifcblenderexport/blenderbim/bim/module/root/operator.py @@ -215,6 +215,8 @@ class UnlinkObject(bpy.types.Operator): for obj in objects: if obj.BIMObjectProperties.ifc_definition_id: obj.BIMObjectProperties.ifc_definition_id = 0 + if "Ifc" in obj.name and "/" in obj.name: + obj.name = "/".join(obj.name.split("/")[1:]) return {"FINISHED"} diff --git a/src/ifcblenderexport/blenderbim/bim/module/root/ui.py b/src/ifcblenderexport/blenderbim/bim/module/root/ui.py index 88053fedf8..058de8afe7 100644 --- a/src/ifcblenderexport/blenderbim/bim/module/root/ui.py +++ b/src/ifcblenderexport/blenderbim/bim/module/root/ui.py @@ -19,7 +19,12 @@ class BIM_PT_class(Panel): props = context.active_object.BIMObjectProperties if props.ifc_definition_id: if props.ifc_definition_id not in Data.products: - Data.load(props.ifc_definition_id) + try: + Data.load(props.ifc_definition_id) + except: + row = self.layout.row(align=True) + row.label(text="IFC Element Not Found") + row.operator("bim.unlink_object", icon="UNLINKED", text="") if props.is_reassigning_class: row = self.layout.row(align=True) row.operator("bim.reassign_class", icon="CHECKMARK") @@ -35,7 +40,7 @@ class BIM_PT_class(Panel): row = self.layout.row(align=True) row.label(text=name) row.operator("bim.copy_class", icon="DUPLICATE", text="").obj = context.active_object.name - row.operator("bim.unlink_object", icon="UNLINKED", text="").obj = context.active_object.name + row.operator("bim.unlink_object", icon="UNLINKED", text="") row.operator("bim.enable_reassign_class", icon="GREASEPENCIL", text="") row.operator("bim.unassign_class", icon="X", text="").obj = context.active_object.name else: diff --git a/src/ifcblenderexport/blenderbim/bim/module/style/__init__.py b/src/ifcblenderexport/blenderbim/bim/module/style/__init__.py index bd340a126a..590bb7d66e 100644 --- a/src/ifcblenderexport/blenderbim/bim/module/style/__init__.py +++ b/src/ifcblenderexport/blenderbim/bim/module/style/__init__.py @@ -4,6 +4,7 @@ from . import ui, operator classes = ( operator.AddStyle, operator.EditStyle, + operator.UnlinkStyle, ui.BIM_PT_style, ) diff --git a/src/ifcblenderexport/blenderbim/bim/module/style/operator.py b/src/ifcblenderexport/blenderbim/bim/module/style/operator.py index 204a4e4385..62cce46f0b 100644 --- a/src/ifcblenderexport/blenderbim/bim/module/style/operator.py +++ b/src/ifcblenderexport/blenderbim/bim/module/style/operator.py @@ -3,8 +3,6 @@ import blenderbim.bim.module.style.add_style as add_style import blenderbim.bim.module.style.edit_style as edit_style from blenderbim.bim.ifc import IfcStore -# from blenderbim.bim.module.spatial.data import Data - def get_colour_settings(material): transparency = material.diffuse_color[3] @@ -48,3 +46,17 @@ class AddStyle(bpy.types.Operator): style = add_style.Usecase(self.file, settings).execute() material.BIMMaterialProperties.ifc_style_id = int(style.id()) return {"FINISHED"} + + +class UnlinkStyle(bpy.types.Operator): + bl_idname = "bim.unlink_style" + bl_label = "Unlink Style" + material: bpy.props.StringProperty() + + def execute(self, context): + self.file = IfcStore.get_file() + material = bpy.data.materials.get(self.material) + material.BIMMaterialProperties.ifc_style_id = 0 + if "Ifc" in material.name and "/" in material.name: + material.name = "/".join(material.name.split("/")[1:]) + return {"FINISHED"} diff --git a/src/ifcblenderexport/blenderbim/bim/module/style/ui.py b/src/ifcblenderexport/blenderbim/bim/module/style/ui.py index 408e42a846..b34f4595fb 100644 --- a/src/ifcblenderexport/blenderbim/bim/module/style/ui.py +++ b/src/ifcblenderexport/blenderbim/bim/module/style/ui.py @@ -19,8 +19,10 @@ class BIM_PT_style(Panel): def draw(self, context): props = context.active_object.active_material.BIMMaterialProperties - row = self.layout.row() + row = self.layout.row(align=True) if props.ifc_style_id: row.operator("bim.edit_style", icon="GREASEPENCIL") + op = row.operator("bim.unlink_style", icon="UNLINKED", text="") + op.material = context.active_object.active_material.name else: row.operator("bim.add_style", icon="ADD")