#2048. Blender materials, IFC materials and IFC presentation style names are now bi-directional.

This commit is contained in:
Dion Moult
2022-03-27 14:43:05 +11:00
parent ca03a88601
commit 28336140ca
3 changed files with 19 additions and 11 deletions
+2 -5
View File
@@ -26,9 +26,7 @@ from blenderbim.bim.module.drawing.prop import RasterStyleProperty
from bpy.app.handlers import persistent from bpy.app.handlers import persistent
from blenderbim.bim.ifc import IfcStore from blenderbim.bim.ifc import IfcStore
from blenderbim.bim.module.owner.prop import get_user_person, get_user_organisation from blenderbim.bim.module.owner.prop import get_user_person, get_user_organisation
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
@@ -68,11 +66,10 @@ def name_callback(obj, data):
if isinstance(obj, bpy.types.Material): if isinstance(obj, bpy.types.Material):
if obj.BIMObjectProperties.ifc_definition_id: if obj.BIMObjectProperties.ifc_definition_id:
IfcStore.get_file().by_id(obj.BIMObjectProperties.ifc_definition_id).Name = obj.name IfcStore.get_file().by_id(obj.BIMObjectProperties.ifc_definition_id).Name = obj.name
AttributeData.load(IfcStore.get_file(), obj.BIMObjectProperties.ifc_definition_id)
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) refresh_ui_data()
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:
@@ -96,7 +93,7 @@ def name_callback(obj, data):
if element.is_a("IfcTypeProduct"): if element.is_a("IfcTypeProduct"):
TypeData.purge() TypeData.purge()
element.Name = "/".join(obj.name.split("/")[1:]) element.Name = "/".join(obj.name.split("/")[1:])
AttributeData.load(IfcStore.get_file(), obj.BIMObjectProperties.ifc_definition_id) refresh_ui_data()
def color_callback(obj, data): def color_callback(obj, data):
@@ -27,6 +27,7 @@ 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_pre_listener("attribute.edit_attributes", "BlenderBIM.Root.SyncName", root.sync_name)
ifcopenshell.api.add_pre_listener("style.edit_presentation_style", "BlenderBIM.Root.SyncStyleName", 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
@@ -17,24 +17,34 @@
# along with BlenderBIM Add-on. If not, see <http://www.gnu.org/licenses/>. # along with BlenderBIM Add-on. If not, see <http://www.gnu.org/licenses/>.
import bpy import bpy
import blenderbim.bim.handler
import blenderbim.tool as tool
from blenderbim.bim.ifc import IfcStore from blenderbim.bim.ifc import IfcStore
from ifcopenshell.api.style.data import Data as StyleData
def sync_name(usecase_path, ifc_file, settings): def sync_name(usecase_path, ifc_file, settings):
if usecase_path == "attribute.edit_attributes":
element = settings["product"]
elif usecase_path == "style.edit_presentation_style":
element = settings["style"]
if "Name" not in settings["attributes"]: if "Name" not in settings["attributes"]:
return return
obj = IfcStore.get_element(settings["product"].id()) obj = tool.Ifc.get_object(element)
if not obj: if not obj:
return return
if isinstance(obj, bpy.types.Object): if isinstance(obj, bpy.types.Object):
new_name = "{}/{}".format(settings["product"].is_a(), settings["attributes"]["Name"] or "Unnamed") new_name = "{}/{}".format(element.is_a(), settings["attributes"]["Name"] or "Unnamed")
elif isinstance(obj, bpy.types.Material): elif isinstance(obj, bpy.types.Material):
new_name = settings["attributes"]["Name"] or "Unnamed" new_name = settings["attributes"]["Name"] or "Unnamed"
if obj.BIMMaterialProperties.ifc_style_id: material = tool.Ifc.get_entity(obj)
IfcStore.get_file().by_id(obj.BIMMaterialProperties.ifc_style_id).Name = new_name if material and material != element:
StyleData.load(IfcStore.get_file(), obj.BIMMaterialProperties.ifc_style_id) material.Name = new_name
style = tool.Style.get_style(obj)
if style and style != element:
style.Name = new_name
collection = bpy.data.collections.get(obj.name) collection = bpy.data.collections.get(obj.name)
if collection: if collection:
collection.name = new_name collection.name = new_name
obj.name = new_name obj.name = new_name
blenderbim.bim.handler.refresh_ui_data()