mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-09-21 14:23:53 +00:00
set_material_name to prevent triggering name callback if it's not necessary
This commit is contained in:
@@ -56,9 +56,13 @@ def name_callback(obj: Union[bpy.types.Object, bpy.types.Material], data: str) -
|
|||||||
return
|
return
|
||||||
|
|
||||||
if isinstance(obj, bpy.types.Material):
|
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
|
IfcStore.get_file().by_id(ifc_definition_id).Name = obj.name
|
||||||
refresh_ui_data()
|
refresh_ui_data()
|
||||||
return
|
return
|
||||||
|
|
||||||
if not obj.BIMObjectProperties.ifc_definition_id:
|
if not obj.BIMObjectProperties.ifc_definition_id:
|
||||||
|
|||||||
@@ -848,7 +848,8 @@ class EditSurfaceStyle(bpy.types.Operator, tool.Ifc.Operator):
|
|||||||
new_name = attributes_data["Name"]
|
new_name = attributes_data["Name"]
|
||||||
if new_name != original_name:
|
if new_name != original_name:
|
||||||
material = tool.Ifc.get_object(self.surface_style)
|
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:
|
else:
|
||||||
attributes = tool.Style.get_style_ui_props_attributes(self.surface_style.is_a())
|
attributes = tool.Style.get_style_ui_props_attributes(self.surface_style.is_a())
|
||||||
assert attributes
|
assert attributes
|
||||||
|
|||||||
@@ -294,3 +294,4 @@ class BIMStyleProperties(PropertyGroup):
|
|||||||
default="Shading",
|
default="Shading",
|
||||||
update=update_shading_style,
|
update=update_shading_style,
|
||||||
)
|
)
|
||||||
|
is_renaming: BoolProperty(description="Used to prevent triggering handler callback.", default=False)
|
||||||
|
|||||||
@@ -402,6 +402,15 @@ class Root(bonsai.core.tool.Root):
|
|||||||
obj.BIMObjectProperties.is_renaming = True
|
obj.BIMObjectProperties.is_renaming = True
|
||||||
obj.name = name # The handler will trigger, and reset is_renaming to False
|
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
|
@classmethod
|
||||||
def unlink_object(cls, obj: bpy.types.Object) -> None:
|
def unlink_object(cls, obj: bpy.types.Object) -> None:
|
||||||
"""Purge all IFC data associated with a Blender object.
|
"""Purge all IFC data associated with a Blender object.
|
||||||
|
|||||||
Reference in New Issue
Block a user