diff --git a/src/bonsai/bonsai/bim/module/model/workspace.py b/src/bonsai/bonsai/bim/module/model/workspace.py index 82feb3dd4d..f5ead43824 100644 --- a/src/bonsai/bonsai/bim/module/model/workspace.py +++ b/src/bonsai/bonsai/bim/module/model/workspace.py @@ -972,14 +972,15 @@ class Hotkey(bpy.types.Operator, tool.Ifc.Operator): relating_type = tool.Ifc.get().by_id(int(relating_type_id)) - has_only_walls_selected = tool.Blender.get_selected_objects() and all( - (e := tool.Ifc.get_entity(o)) and e.is_a("IfcWall") for o in tool.Blender.get_selected_objects() + has_only_walls_selected = tool.Blender.get_selected_objects(include_active=False) and all( + (e := tool.Ifc.get_entity(o)) and e.is_a("IfcWall") + for o in tool.Blender.get_selected_objects(include_active=False) ) if tool.Model.get_usage_type(relating_type) == "LAYER3" and has_only_walls_selected: return bpy.ops.bim.draw_slab_from_wall("INVOKE_DEFAULT") elif ( - (active_obj := tool.Blender.get_active_object()) + (active_obj := tool.Blender.get_active_object(is_selected=True)) and (active_element := tool.Ifc.get_entity(active_obj)) and active_element.is_a("IfcSlab") and tool.Model.get_usage_type(relating_type) == "LAYER2" diff --git a/src/bonsai/bonsai/tool/blender.py b/src/bonsai/bonsai/tool/blender.py index 19eda84dec..0035074c5f 100644 --- a/src/bonsai/bonsai/tool/blender.py +++ b/src/bonsai/bonsai/tool/blender.py @@ -144,17 +144,21 @@ class Blender(bonsai.core.tool.Blender): return f"{name} {i}" @classmethod - def get_active_object(cls) -> bpy.types.Object: - return getattr(bpy.context, "active_object", None) or bpy.context.view_layer.objects.active + def get_active_object(cls, is_selected: bool = False) -> bpy.types.Object: + obj = getattr(bpy.context, "active_object", None) or bpy.context.view_layer.objects.active + if not is_selected: + return obj + if obj in cls.get_selected_objects(include_active=False): + return obj @classmethod - def get_selected_objects(cls) -> set[bpy.types.Object]: + def get_selected_objects(cls, include_active: bool = True) -> set[bpy.types.Object]: """Get selected objects including active object.""" if selected_objects := getattr(bpy.context, "selected_objects", None): - if active_obj := cls.get_active_object(): + if include_active and (active_obj := cls.get_active_object()): return set(selected_objects + [active_obj]) return set(selected_objects) - if active_obj := cls.get_active_object(): + if include_active and (active_obj := cls.get_active_object()): return {active_obj} return set()