Fix #1337. Changing the name of a Blender object now also auto changes its IFC name.

This commit is contained in:
Dion Moult
2021-02-23 21:15:27 +11:00
parent 15cf3f5afd
commit d50c89abee
2 changed files with 13 additions and 0 deletions
@@ -3,6 +3,7 @@ import json
import blenderbim.bim.decoration as decoration import blenderbim.bim.decoration as decoration
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.attribute.data import Data as AttributeData
def mode_callback(obj, data): def mode_callback(obj, data):
@@ -19,6 +20,17 @@ def mode_callback(obj, data):
bpy.ops.bim.update_mesh_representation(obj=obj.name) bpy.ops.bim.update_mesh_representation(obj=obj.name)
def name_callback(obj, data):
# Blender material names are up to 63 UTF-8 bytes
if not obj.BIMObjectProperties.ifc_definition_id or "/" not in obj.name or len(bytes(obj.name, "utf-8")) >= 63:
return
element = IfcStore.get_file().by_id(obj.BIMObjectProperties.ifc_definition_id)
if not element.is_a("IfcRoot"):
return
element.Name = "/".join(obj.name.split("/")[1:])
AttributeData.load(obj.BIMObjectProperties.ifc_definition_id)
def subscribe_to(object, data_path, callback): def subscribe_to(object, data_path, callback):
subscribe_to = object.path_resolve(data_path, False) subscribe_to = object.path_resolve(data_path, False)
bpy.msgbus.subscribe_rna( bpy.msgbus.subscribe_rna(
@@ -38,6 +38,7 @@ class IfcStore:
IfcStore.guid_map[element.GlobalId] = obj IfcStore.guid_map[element.GlobalId] = obj
obj.BIMObjectProperties.ifc_definition_id = element.id() obj.BIMObjectProperties.ifc_definition_id = element.id()
blenderbim.bim.handler.subscribe_to(obj, "mode", blenderbim.bim.handler.mode_callback) blenderbim.bim.handler.subscribe_to(obj, "mode", blenderbim.bim.handler.mode_callback)
blenderbim.bim.handler.subscribe_to(obj, "name", blenderbim.bim.handler.name_callback)
@staticmethod @staticmethod
def unlink_element(element, obj=None): def unlink_element(element, obj=None):