From a92306d41391265d95043b63f07eba560e1c24a0 Mon Sep 17 00:00:00 2001 From: Dion Moult Date: Wed, 5 Feb 2025 20:28:29 +1100 Subject: [PATCH] Fix #6097. Be more defensive against selection state when moving objects into new containers. --- src/bonsai/bonsai/bim/module/spatial/operator.py | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/src/bonsai/bonsai/bim/module/spatial/operator.py b/src/bonsai/bonsai/bim/module/spatial/operator.py index b4f92dc164..a7babed7f9 100644 --- a/src/bonsai/bonsai/bim/module/spatial/operator.py +++ b/src/bonsai/bonsai/bim/module/spatial/operator.py @@ -92,12 +92,18 @@ class AssignContainer(bpy.types.Operator, tool.Ifc.Operator): return self.execute(context) def _execute(self, context): - props = context.active_object.BIMObjectSpatialProperties if self.container: container = tool.Ifc.get().by_id(self.container) - elif (container_obj := props.container_obj) and (container := tool.Ifc.get_entity(container_obj)): + elif ( + (obj := tool.Blender.get_active_object()) + and (props := obj.BIMObjectSpatialProperties) + and (container_obj := props.container_obj) + and (container := tool.Ifc.get_entity(container_obj)) + ): pass - for element_obj in context.selected_objects: + else: + return + for element_obj in tool.Blender.get_selected_objects(): if self.remove_from_other_containers: for col in element_obj.users_collection[:]: col.objects.unlink(element_obj)