From 110daf4ca7df6729cc9e0c72c33984d5f8be21c3 Mon Sep 17 00:00:00 2001 From: Dion Moult Date: Thu, 29 Jul 2021 17:03:06 +1000 Subject: [PATCH] Fix #1592. Material name changes are now auto synced with style names. --- src/blenderbim/blenderbim/bim/handler.py | 2 ++ .../bim/module/attribute/operator.py | 6 ----- .../blenderbim/bim/module/model/handler.py | 6 ++++- .../blenderbim/bim/module/model/root.py | 22 +++++++++++++++++++ 4 files changed, 29 insertions(+), 7 deletions(-) create mode 100644 src/blenderbim/blenderbim/bim/module/model/root.py diff --git a/src/blenderbim/blenderbim/bim/handler.py b/src/blenderbim/blenderbim/bim/handler.py index 063f67d194..7c02de271f 100644 --- a/src/blenderbim/blenderbim/bim/handler.py +++ b/src/blenderbim/blenderbim/bim/handler.py @@ -6,6 +6,7 @@ from bpy.app.handlers import persistent from blenderbim.bim.ifc import IfcStore from ifcopenshell.api.attribute.data import Data as AttributeData from ifcopenshell.api.material.data import Data as MaterialData +from ifcopenshell.api.style.data import Data as StyleData from ifcopenshell.api.type.data import Data as TypeData @@ -51,6 +52,7 @@ def name_callback(obj, data): MaterialData.load_materials() if obj.BIMMaterialProperties.ifc_style_id: IfcStore.get_file().by_id(obj.BIMMaterialProperties.ifc_style_id).Name = obj.name + StyleData.load(IfcStore.get_file(), obj.BIMMaterialProperties.ifc_style_id) return if not obj.BIMObjectProperties.ifc_definition_id or "/" not in obj.name: diff --git a/src/blenderbim/blenderbim/bim/module/attribute/operator.py b/src/blenderbim/blenderbim/bim/module/attribute/operator.py index 8d0432da77..24989af37f 100644 --- a/src/blenderbim/blenderbim/bim/module/attribute/operator.py +++ b/src/blenderbim/blenderbim/bim/module/attribute/operator.py @@ -104,12 +104,6 @@ class EditAttributes(bpy.types.Operator): ifcopenshell.api.run( "attribute.edit_attributes", self.file, **{"product": product, "attributes": attributes} ) - if "Name" in attributes: - new_name = "{}/{}".format(product.is_a(), product.Name or "Unnamed") - collection = bpy.data.collections.get(obj.name) - if collection: - collection.name = new_name - obj.name = new_name Data.load(IfcStore.get_file(), oprops.ifc_definition_id) bpy.ops.bim.disable_editing_attributes(obj=obj.name, obj_type=self.obj_type) return {"FINISHED"} diff --git a/src/blenderbim/blenderbim/bim/module/model/handler.py b/src/blenderbim/blenderbim/bim/module/model/handler.py index 7dc1fd8e43..559a5ad169 100644 --- a/src/blenderbim/blenderbim/bim/module/model/handler.py +++ b/src/blenderbim/blenderbim/bim/module/model/handler.py @@ -1,13 +1,17 @@ import bpy import ifcopenshell import ifcopenshell.api -from blenderbim.bim.module.model import product, wall, slab, profile, opening +from blenderbim.bim.module.model import root, product, wall, slab, profile, opening from blenderbim.bim.ifc import IfcStore from bpy.app.handlers import persistent @persistent def load_post(*args): + ifcopenshell.api.add_pre_listener( + "attribute.edit_attributes", "BlenderBIM.Root.SyncName", root.sync_name + ) + ifcopenshell.api.add_post_listener( "geometry.add_representation", "BlenderBIM.Product.GenerateBox", product.generate_box ) diff --git a/src/blenderbim/blenderbim/bim/module/model/root.py b/src/blenderbim/blenderbim/bim/module/model/root.py new file mode 100644 index 0000000000..729d477b94 --- /dev/null +++ b/src/blenderbim/blenderbim/bim/module/model/root.py @@ -0,0 +1,22 @@ +import bpy +from blenderbim.bim.ifc import IfcStore +from ifcopenshell.api.style.data import Data as StyleData + + +def sync_name(usecase_path, ifc_file, settings): + if "Name" not in settings["attributes"]: + return + obj = IfcStore.get_element(settings["product"].id()) + if not obj: + return + if isinstance(obj, bpy.types.Object): + new_name = "{}/{}".format(settings["product"].is_a(), settings["attributes"]["Name"] or "Unnamed") + elif isinstance(obj, bpy.types.Material): + new_name = settings["attributes"]["Name"] or "Unnamed" + if obj.BIMMaterialProperties.ifc_style_id: + IfcStore.get_file().by_id(obj.BIMMaterialProperties.ifc_style_id).Name = new_name + StyleData.load(IfcStore.get_file(), obj.BIMMaterialProperties.ifc_style_id) + collection = bpy.data.collections.get(obj.name) + if collection: + collection.name = new_name + obj.name = new_name