Fix #1592. Material name changes are now auto synced with style names.

This commit is contained in:
Dion Moult
2021-07-29 17:03:06 +10:00
parent 6bf692b44d
commit 110daf4ca7
4 changed files with 29 additions and 7 deletions
+2
View File
@@ -6,6 +6,7 @@ from bpy.app.handlers import persistent
from blenderbim.bim.ifc import IfcStore from blenderbim.bim.ifc import IfcStore
from ifcopenshell.api.attribute.data import Data as AttributeData from ifcopenshell.api.attribute.data import Data as AttributeData
from ifcopenshell.api.material.data import Data as MaterialData 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 from ifcopenshell.api.type.data import Data as TypeData
@@ -51,6 +52,7 @@ def name_callback(obj, data):
MaterialData.load_materials() MaterialData.load_materials()
if obj.BIMMaterialProperties.ifc_style_id: if obj.BIMMaterialProperties.ifc_style_id:
IfcStore.get_file().by_id(obj.BIMMaterialProperties.ifc_style_id).Name = obj.name IfcStore.get_file().by_id(obj.BIMMaterialProperties.ifc_style_id).Name = obj.name
StyleData.load(IfcStore.get_file(), obj.BIMMaterialProperties.ifc_style_id)
return return
if not obj.BIMObjectProperties.ifc_definition_id or "/" not in obj.name: if not obj.BIMObjectProperties.ifc_definition_id or "/" not in obj.name:
@@ -104,12 +104,6 @@ class EditAttributes(bpy.types.Operator):
ifcopenshell.api.run( ifcopenshell.api.run(
"attribute.edit_attributes", self.file, **{"product": product, "attributes": attributes} "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) Data.load(IfcStore.get_file(), oprops.ifc_definition_id)
bpy.ops.bim.disable_editing_attributes(obj=obj.name, obj_type=self.obj_type) bpy.ops.bim.disable_editing_attributes(obj=obj.name, obj_type=self.obj_type)
return {"FINISHED"} return {"FINISHED"}
@@ -1,13 +1,17 @@
import bpy import bpy
import ifcopenshell import ifcopenshell
import ifcopenshell.api 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 blenderbim.bim.ifc import IfcStore
from bpy.app.handlers import persistent from bpy.app.handlers import persistent
@persistent @persistent
def load_post(*args): def load_post(*args):
ifcopenshell.api.add_pre_listener(
"attribute.edit_attributes", "BlenderBIM.Root.SyncName", root.sync_name
)
ifcopenshell.api.add_post_listener( ifcopenshell.api.add_post_listener(
"geometry.add_representation", "BlenderBIM.Product.GenerateBox", product.generate_box "geometry.add_representation", "BlenderBIM.Product.GenerateBox", product.generate_box
) )
@@ -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