set_material_name to prevent triggering name callback if it's not necessary

This commit is contained in:
Andrej730
2025-01-24 18:39:51 +05:00
parent 57150e9f63
commit fbab13339c
4 changed files with 18 additions and 3 deletions
+6 -2
View File
@@ -56,9 +56,13 @@ def name_callback(obj: Union[bpy.types.Object, bpy.types.Material], data: str) -
return
if isinstance(obj, bpy.types.Material):
if ifc_definition_id := obj.BIMStyleProperties.ifc_definition_id:
props = obj.BIMStyleProperties
if ifc_definition_id := props.ifc_definition_id:
if props.is_renaming:
props.is_renmaing = False
return
IfcStore.get_file().by_id(ifc_definition_id).Name = obj.name
refresh_ui_data()
refresh_ui_data()
return
if not obj.BIMObjectProperties.ifc_definition_id:
@@ -848,7 +848,8 @@ class EditSurfaceStyle(bpy.types.Operator, tool.Ifc.Operator):
new_name = attributes_data["Name"]
if new_name != original_name:
material = tool.Ifc.get_object(self.surface_style)
material.name = new_name or "Unnamed"
assert isinstance(material, bpy.types.Material)
tool.Root.set_material_name(material, new_name or "Unnamed")
else:
attributes = tool.Style.get_style_ui_props_attributes(self.surface_style.is_a())
assert attributes
@@ -294,3 +294,4 @@ class BIMStyleProperties(PropertyGroup):
default="Shading",
update=update_shading_style,
)
is_renaming: BoolProperty(description="Used to prevent triggering handler callback.", default=False)
+9
View File
@@ -402,6 +402,15 @@ class Root(bonsai.core.tool.Root):
obj.BIMObjectProperties.is_renaming = True
obj.name = name # The handler will trigger, and reset is_renaming to False
@classmethod
def set_material_name(cls, material: bpy.types.Material, name: str) -> None:
"""Rename material without triggerring name callback and unnecessary writing to IFC."""
if material.name == name:
return
props = material.BIMStyleProperties
props.is_renaming = True
material.name = name # The handler will trigger, and reset is_renaming to False.
@classmethod
def unlink_object(cls, obj: bpy.types.Object) -> None:
"""Purge all IFC data associated with a Blender object.