Fix #6013. Fix bug where Blender object names weren't updated when using copy attributes.

This commit is contained in:
Dion Moult
2025-01-22 22:54:58 +11:00
parent 4adca79301
commit 3dfc7097b2
4 changed files with 11 additions and 16 deletions
@@ -141,11 +141,7 @@ class EditAttributes(bpy.types.Operator, tool.Ifc.Operator):
attributes = bonsai.bim.helper.export_attributes(props.attributes, callback=callback)
ifcopenshell.api.run("attribute.edit_attributes", self.file, product=product, attributes=attributes)
# Ensure Blender doesn't reindex objects if it's not necessary.
# Can't rely on obj.name to detect changed name as it may have Blender indices.
if tool.Loader.get_name(product) != object_name:
tool.Root.set_object_name(obj, product)
tool.Root.set_object_name(obj, product)
bpy.ops.bim.disable_editing_attributes(obj=obj.name)
def _execute(self, context):
@@ -208,7 +204,7 @@ class CopyAttributeToSelection(bpy.types.Operator, tool.Ifc.Operator):
value = context.active_object.BIMAttributeProperties.attributes.get(self.name).get_value()
i = 0
for obj in tool.Blender.get_selected_objects():
success = core.copy_attribute_to_selection(tool.Ifc, name=self.name, value=value, obj=obj)
success = core.copy_attribute_to_selection(tool.Ifc, tool.Root, name=self.name, value=value, obj=obj)
if success:
i += 1
self.report({"INFO"}, f"Attribute was successfully copied to {i} elements.")
+1 -3
View File
@@ -25,9 +25,7 @@ from typing import Any
def sync_name(usecase_path: str, ifc_file: ifcopenshell.file, settings: dict[str, Any]) -> None:
if usecase_path == "attribute.edit_attributes":
element = settings["product"]
elif usecase_path == "style.edit_presentation_style":
if usecase_path == "style.edit_presentation_style":
element = settings["style"]
else:
raise Exception(f"Unsupported usecase: '{usecase_path}'.")
+4 -3
View File
@@ -25,11 +25,12 @@ if TYPE_CHECKING:
import bonsai.tool as tool
def copy_attribute_to_selection(ifc: tool.Ifc, name: str, value: Union[str, None], obj: bpy.types.Object) -> bool:
element = ifc.get_entity(obj)
if element:
def copy_attribute_to_selection(ifc: tool.Ifc, root: tool.Root, name: str, value: Union[str, None], obj: bpy.types.Object) -> bool:
if element := ifc.get_entity(obj):
try:
ifc.run("attribute.edit_attributes", product=element, attributes={name: value})
if name in ("Name", "AxisTag"):
root.set_object_name(obj, element)
return True
except:
pass
+4 -4
View File
@@ -397,10 +397,10 @@ class Root(bonsai.core.tool.Root):
@classmethod
def set_object_name(cls, obj: bpy.types.Object, element: ifcopenshell.entity_instance) -> None:
# This disables the Blender name event handler
obj.BIMObjectProperties.is_renaming = True
obj.name = tool.Loader.get_name(element)
obj.BIMObjectProperties.is_renaming = False
name = tool.Loader.get_name(element)
if obj.name != name:
obj.BIMObjectProperties.is_renaming = True
obj.name = name # The handler will trigger, and reset is_renaming to False
@classmethod
def unlink_object(cls, obj: bpy.types.Object) -> None: