From 4874f7770b9c0ffa30022855cc611fe6f3c7d9fd Mon Sep 17 00:00:00 2001 From: Ryan Schultz Date: Sat, 3 Jan 2026 16:52:10 -0600 Subject: [PATCH] Closes #3764: When switching an instance to a different beam type, preserve the CardinalPoint. --- src/bonsai/bonsai/core/type.py | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/src/bonsai/bonsai/core/type.py b/src/bonsai/bonsai/core/type.py index 226f00c461..7926c53ff1 100644 --- a/src/bonsai/bonsai/core/type.py +++ b/src/bonsai/bonsai/core/type.py @@ -19,6 +19,7 @@ from __future__ import annotations import bonsai.core.geometry from typing import TYPE_CHECKING, Optional +import ifcopenshell.util.element if TYPE_CHECKING: import bpy @@ -32,14 +33,34 @@ def assign_type( element: ifcopenshell.entity_instance, type: ifcopenshell.entity_instance, ) -> None: + + + # Get the instance's current CardinalPoint before type assignment + instance_cardinal_point = None + instance_material = ifcopenshell.util.element.get_material(element) + if instance_material and instance_material.is_a("IfcMaterialProfileSetUsage"): + instance_cardinal_point = instance_material.CardinalPoint + ifc.run("type.assign_type", related_objects=[element], relating_type=type) obj = ifc.get_object(element) + if type_tool.has_material_usage(element): - pass # for now, representation regeneration handled by API listeners + # Restore the instance's CardinalPoint to the new material usage + if instance_cardinal_point is not None: + new_instance_material = ifcopenshell.util.element.get_material(element) + if new_instance_material and new_instance_material.is_a("IfcMaterialProfileSetUsage"): + if new_instance_material.CardinalPoint != instance_cardinal_point: + new_instance_material.CardinalPoint = instance_cardinal_point + + # Force representation regeneration + from bonsai.bim.module.model.profile import DumbProfileRecalculator + DumbProfileRecalculator().recalculate([obj]) + # for now, representation regeneration handled by API listeners else: type_data = type_tool.get_object_data(ifc.get_object(type)) if type_data: type_tool.change_object_data(obj, type_data, is_global=False) + type_tool.disable_editing(obj)