mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-09-23 15:56:18 +00:00
Closes #3764: When switching an instance to a different beam type, preserve the CardinalPoint.
This commit is contained in:
@@ -19,6 +19,7 @@
|
|||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
import bonsai.core.geometry
|
import bonsai.core.geometry
|
||||||
from typing import TYPE_CHECKING, Optional
|
from typing import TYPE_CHECKING, Optional
|
||||||
|
import ifcopenshell.util.element
|
||||||
|
|
||||||
if TYPE_CHECKING:
|
if TYPE_CHECKING:
|
||||||
import bpy
|
import bpy
|
||||||
@@ -32,14 +33,34 @@ def assign_type(
|
|||||||
element: ifcopenshell.entity_instance,
|
element: ifcopenshell.entity_instance,
|
||||||
type: ifcopenshell.entity_instance,
|
type: ifcopenshell.entity_instance,
|
||||||
) -> None:
|
) -> 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)
|
ifc.run("type.assign_type", related_objects=[element], relating_type=type)
|
||||||
obj = ifc.get_object(element)
|
obj = ifc.get_object(element)
|
||||||
|
|
||||||
if type_tool.has_material_usage(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:
|
else:
|
||||||
type_data = type_tool.get_object_data(ifc.get_object(type))
|
type_data = type_tool.get_object_data(ifc.get_object(type))
|
||||||
if type_data:
|
if type_data:
|
||||||
type_tool.change_object_data(obj, type_data, is_global=False)
|
type_tool.change_object_data(obj, type_data, is_global=False)
|
||||||
|
|
||||||
type_tool.disable_editing(obj)
|
type_tool.disable_editing(obj)
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user