Closes #3764: When switching an instance to a different beam type, preserve the CardinalPoint.

This commit is contained in:
Ryan Schultz
2026-01-03 16:52:10 -06:00
parent 56861b9403
commit 4874f7770b
+22 -1
View File
@@ -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)