Source code for linkforge.blender.operators.selection_ops

"""Operators for viewport selection and tree navigation."""

from __future__ import annotations

import contextlib

import bpy
from bpy.props import StringProperty
from bpy.types import Context, Operator

from ..utils.decorators import OperatorReturn, safe_execute
from ..utils.scene_utils import build_tree_from_stats, get_robot_statistics


[docs] class LINKFORGE_OT_select_tree_object(Operator): """Select object from kinematic tree.""" bl_idname = "linkforge.select_tree_object" bl_label = "Select Object" bl_description = "Select this object in the 3D viewport" bl_options = {"REGISTER", "UNDO"} object_name: StringProperty( # type: ignore name="Object Name", description="Name of the object to select" ) object_type: StringProperty( # type: ignore name="Object Type", description="Type of object (link, joint, sensor)", default="" )
[docs] @safe_execute def execute(self, context: Context) -> OperatorReturn: """Execute the operator. Args: context: The execution context. Returns: Set containing the execution state (e.g., {'FINISHED'} or {'CANCELLED'}). """ scene = context.scene if not scene: return {"CANCELLED"} obj = scene.objects.get(self.object_name) if not obj: self.report({"WARNING"}, f"Object '{self.object_name}' not found") return {"CANCELLED"} # Deselect all bpy.ops.object.select_all(action="DESELECT") # Select and activate the object obj.select_set(True) vl = context.view_layer if vl: vl.objects.active = obj return {"FINISHED"}
# Registration classes = [ LINKFORGE_OT_select_tree_object, LINKFORGE_OT_select_root_link, ]
[docs] def register() -> None: """Register operators.""" for cls in classes: try: bpy.utils.register_class(cls) except ValueError: bpy.utils.unregister_class(cls) bpy.utils.register_class(cls)
[docs] def unregister() -> None: """Unregister operators.""" for cls in reversed(classes): with contextlib.suppress(RuntimeError): bpy.utils.unregister_class(cls)
if __name__ == "__main__": register()