From d8102d848d68bc581081f324ba352cea6ae4968b Mon Sep 17 00:00:00 2001 From: Andrej730 Date: Thu, 10 Apr 2025 17:37:08 +0500 Subject: [PATCH] Fix bug with the first object rename after class assignment The problem was that during class assignment, it was setting the object name and `is_renaming` flag but only then linking to IFC. Since object wasn't linked to IFC, name callback wasn't triggered and `is_renaming` wasn't reset and first rename wouldn't work. Now it's just not setting the flag if object is not linked to IFC, as there's no callback then and don't need to protect from it. --- src/bonsai/bonsai/bim/prop.py | 9 ++++++++- src/bonsai/bonsai/tool/root.py | 6 ++++-- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/src/bonsai/bonsai/bim/prop.py b/src/bonsai/bonsai/bim/prop.py index af378bb8f4..45128271b1 100644 --- a/src/bonsai/bonsai/bim/prop.py +++ b/src/bonsai/bonsai/bim/prop.py @@ -620,7 +620,14 @@ class BIMObjectProperties(PropertyGroup): ) cartesian_point_offset: StringProperty(name="Cartesian Point Offset") is_reassigning_class: BoolProperty(name="Is Reassigning Class") - is_renaming: BoolProperty(name="Is Renaming", default=False) + is_renaming: BoolProperty( + name="Is Renaming", + description=( + "Flag to ensure object name callback wouldn't write new name to IFC. " + "Automatically reset to `False` after the next callback." + ), + default=False, + ) location_checksum: StringProperty(name="Location Checksum") rotation_checksum: StringProperty(name="Rotation Checksum") diff --git a/src/bonsai/bonsai/tool/root.py b/src/bonsai/bonsai/tool/root.py index bb6aa116c0..5c67e20066 100644 --- a/src/bonsai/bonsai/tool/root.py +++ b/src/bonsai/bonsai/tool/root.py @@ -419,7 +419,9 @@ class Root(bonsai.core.tool.Root): name = tool.Loader.get_name(element) if obj.name != name: props = tool.Blender.get_object_bim_props(obj) - props.is_renaming = True + # If it's not an IFC object, then it doesn't have a name callback. + # So, we need to protect it writing to IFC. + props.is_renaming = bool(tool.Ifc.get_entity(obj)) obj.name = name # The handler will trigger, and reset is_renaming to False @classmethod @@ -428,7 +430,7 @@ class Root(bonsai.core.tool.Root): if material.name == name: return msprops = tool.Style.get_material_style_props(material) - msprops.is_renaming = True + msprops.is_renaming = bool(tool.Ifc.get_entity(material)) material.name = name # The handler will trigger, and reset is_renaming to False. @classmethod