ui_tool_simple.py 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. # This example adds an object mode tool to the toolbar.
  2. # This is just the circle-select and lasso tools tool.
  3. import bpy
  4. from bpy.types import WorkSpaceTool
  5. class MyTool(WorkSpaceTool):
  6. bl_space_type='VIEW_3D'
  7. bl_context_mode='OBJECT'
  8. # The prefix of the idname should be your add-on name.
  9. bl_idname = "my_template.my_circle_select"
  10. bl_label = "My Circle Select"
  11. bl_description = (
  12. "This is a tooltip\n"
  13. "with multiple lines"
  14. )
  15. bl_icon = "ops.generic.select_circle"
  16. bl_widget = None
  17. bl_keymap = (
  18. ("view3d.select_circle", {"type": 'LEFTMOUSE', "value": 'PRESS'},
  19. {"properties": [("wait_for_input", False)]}),
  20. ("view3d.select_circle", {"type": 'LEFTMOUSE', "value": 'PRESS', "ctrl": True},
  21. {"properties": [("mode", 'SUB'), ("wait_for_input", False)]}),
  22. )
  23. def draw_settings(context, layout, tool):
  24. props = tool.operator_properties("view3d.select_circle")
  25. layout.prop(props, "mode")
  26. layout.prop(props, "radius")
  27. class MyOtherTool(WorkSpaceTool):
  28. bl_space_type='VIEW_3D'
  29. bl_context_mode='OBJECT'
  30. bl_idname = "my_template.my_other_select"
  31. bl_label = "My Lasso Tool Select"
  32. bl_description = (
  33. "This is a tooltip\n"
  34. "with multiple lines"
  35. )
  36. bl_icon = "ops.generic.select_lasso"
  37. bl_widget = None
  38. bl_keymap = (
  39. ("view3d.select_lasso", {"type": 'LEFTMOUSE', "value": 'PRESS'}, None),
  40. ("view3d.select_lasso", {"type": 'LEFTMOUSE', "value": 'PRESS', "ctrl": True},
  41. {"properties": [("mode", 'SUB')]}),
  42. )
  43. def draw_settings(context, layout, tool):
  44. props = tool.operator_properties("view3d.select_lasso")
  45. layout.prop(props, "mode")
  46. def register():
  47. bpy.utils.register_tool(MyTool, after={"builtin.scale_cage"}, separator=True, group=True)
  48. bpy.utils.register_tool(MyOtherTool, after={MyTool.bl_idname})
  49. def unregister():
  50. bpy.utils.unregister_tool(MyTool)
  51. bpy.utils.unregister_tool(MyOtherTool)
  52. if __name__ == "__main__":
  53. register()