mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-09-16 13:46:54 +00:00
Fix #6013. Fix bug where Blender object names weren't updated when using copy attributes.
This commit is contained in:
@@ -141,11 +141,7 @@ class EditAttributes(bpy.types.Operator, tool.Ifc.Operator):
|
|||||||
attributes = bonsai.bim.helper.export_attributes(props.attributes, callback=callback)
|
attributes = bonsai.bim.helper.export_attributes(props.attributes, callback=callback)
|
||||||
ifcopenshell.api.run("attribute.edit_attributes", self.file, product=product, attributes=attributes)
|
ifcopenshell.api.run("attribute.edit_attributes", self.file, product=product, attributes=attributes)
|
||||||
|
|
||||||
# Ensure Blender doesn't reindex objects if it's not necessary.
|
tool.Root.set_object_name(obj, product)
|
||||||
# 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)
|
|
||||||
|
|
||||||
bpy.ops.bim.disable_editing_attributes(obj=obj.name)
|
bpy.ops.bim.disable_editing_attributes(obj=obj.name)
|
||||||
|
|
||||||
def _execute(self, context):
|
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()
|
value = context.active_object.BIMAttributeProperties.attributes.get(self.name).get_value()
|
||||||
i = 0
|
i = 0
|
||||||
for obj in tool.Blender.get_selected_objects():
|
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:
|
if success:
|
||||||
i += 1
|
i += 1
|
||||||
self.report({"INFO"}, f"Attribute was successfully copied to {i} elements.")
|
self.report({"INFO"}, f"Attribute was successfully copied to {i} elements.")
|
||||||
|
|||||||
@@ -25,9 +25,7 @@ from typing import Any
|
|||||||
|
|
||||||
|
|
||||||
def sync_name(usecase_path: str, ifc_file: ifcopenshell.file, settings: dict[str, Any]) -> None:
|
def sync_name(usecase_path: str, ifc_file: ifcopenshell.file, settings: dict[str, Any]) -> None:
|
||||||
if usecase_path == "attribute.edit_attributes":
|
if usecase_path == "style.edit_presentation_style":
|
||||||
element = settings["product"]
|
|
||||||
elif usecase_path == "style.edit_presentation_style":
|
|
||||||
element = settings["style"]
|
element = settings["style"]
|
||||||
else:
|
else:
|
||||||
raise Exception(f"Unsupported usecase: '{usecase_path}'.")
|
raise Exception(f"Unsupported usecase: '{usecase_path}'.")
|
||||||
|
|||||||
@@ -25,11 +25,12 @@ if TYPE_CHECKING:
|
|||||||
import bonsai.tool as tool
|
import bonsai.tool as tool
|
||||||
|
|
||||||
|
|
||||||
def copy_attribute_to_selection(ifc: tool.Ifc, name: str, value: Union[str, None], obj: bpy.types.Object) -> bool:
|
def copy_attribute_to_selection(ifc: tool.Ifc, root: tool.Root, name: str, value: Union[str, None], obj: bpy.types.Object) -> bool:
|
||||||
element = ifc.get_entity(obj)
|
if element := ifc.get_entity(obj):
|
||||||
if element:
|
|
||||||
try:
|
try:
|
||||||
ifc.run("attribute.edit_attributes", product=element, attributes={name: value})
|
ifc.run("attribute.edit_attributes", product=element, attributes={name: value})
|
||||||
|
if name in ("Name", "AxisTag"):
|
||||||
|
root.set_object_name(obj, element)
|
||||||
return True
|
return True
|
||||||
except:
|
except:
|
||||||
pass
|
pass
|
||||||
|
|||||||
@@ -397,10 +397,10 @@ class Root(bonsai.core.tool.Root):
|
|||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def set_object_name(cls, obj: bpy.types.Object, element: ifcopenshell.entity_instance) -> None:
|
def set_object_name(cls, obj: bpy.types.Object, element: ifcopenshell.entity_instance) -> None:
|
||||||
# This disables the Blender name event handler
|
name = tool.Loader.get_name(element)
|
||||||
obj.BIMObjectProperties.is_renaming = True
|
if obj.name != name:
|
||||||
obj.name = tool.Loader.get_name(element)
|
obj.BIMObjectProperties.is_renaming = True
|
||||||
obj.BIMObjectProperties.is_renaming = False
|
obj.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:
|
||||||
|
|||||||
Reference in New Issue
Block a user