[code] Example of Context Menu Command during SelectionTool

selectiontool
command
context_menu
selection
ui::command

#1

Continuing the discussion from Sketchup tool cl@ss name:


Example of Context Menu Command during SelectionTool

Selection_Context_Menu_Command.rb (638 Bytes)

Which looks like:

# encoding : UTF-8

module Author
  module SomePlugin

    extend self

    @@loaded ||= false
    
    COMMAND_NAME = "My Command"

    def my_menu_command(selection)
      # ..code
    end

    if !@@loaded
    
      CMD = UI::Command::new(COMMAND_NAME) {
        my_menu_command(Sketchup.active_model.selection) 
      }
      CMD.set_validation_proc {
        Sketchup.active_model.selection.empty? ? MF_GRAYED : MF_ENABLED
      }

      UI.context_menu_handler {|popup|
        if Sketchup.active_model.tools.active_tool_id == CMD_SELECT
          popup.add_item(CMD)
        end
      }

      @@loaded = true

    end

  end
end