|
SketchUp Ruby API Reference |
The Command class is the preferred class for adding tools to the menus and Ruby toolbars.
Parent: Object
Methods: new , large_icon= , menu_text=, set_validation_proc, small_icon=, status_bar_text=,tooltip=
Example code: commandtests.rb
The new method is used to create a new command.
command = UI::Command.new "menutext" {...}
"menutext" - the text that will appear for this command's menu item if it appears on a menu
... - code that executes the command when the menu item or toolbar item is selected
command - the new Command object
add_separator_to_menu("Draw")
# Adds a Test submenu to the Draw menu where the Tester menu item appears
testmenu = UI.menu("Draw").add_submenu($tStrings.GetString("Test"))
# This menu item simply displays Hello World on the screen when clicked
cmd = UI::Command.new($tStrings.GetString("Tester")) { helloWorld }
testmenu.add_item cmd
The large_icon= method is used to identify
the icon file for the command's large icon.
command = command.large_icon = path
path - the path to the large icon
command - the Command object
toolbar = UI::Toolbar.new "Test"# This toolbar tool simply displays Hello World on the screen when clickedcmd = UI::Command.new($tStrings.GetString("Test")) { helloWorld }cmd.small_icon = "ToolPencilSmall.png"cmd.large_icon = "ToolPencilLarge.png"toolbar = toolbar.add_item cmdtoolbar.show
The menu_text= method is used to set the menu
item name for the command.
command = command.menu_text= "menuitem"
"menuitem" - a string representing
the menu item for the command
command - a Command object
add_separator_to_menu("Draw")# Adds a Test submenu to the Draw menu where the Tester menu item appearstestmenu = UI.menu("Draw").add_submenu($tStrings.GetString("Test"))# This menu item simply displays Hello World on the screen when clickedcmd = UI::Command.new($tStrings.GetString("Tester")) { helloWorld }cmd = cmd.menu_text = "New String"testmenu.add_item cmd
The set_validation_proc method is used to identify the command validation
procedure.
command = menu.set_validation_proc item_id {...}
command - a Command object
Your procedure should return either MF_ENABLED,
MF_DISABLED< MF_CHECKED, MF_UNCHECKED, or MF_GRAYED.
require 'sketchup.rb'def validate_selectionss = Sketchup.active_model.selectionif ss.count == 1return MF_CHECKEDelseif ss.count == 2return MF_ENABLEDelsereturn MF_GRAYEDendendmydir = File.dirname(__FILE__)cmd = UI::Command.new('SayHi') { UI::messagebox 'Hello!' }cmd.menu_text = "Say Hello"cmd.set_validation_proc { validate_selection }cmd.large_icon = mydir + "/myimage.gif"cmd.small_icon = mydir + "/myimage.gif"
UI.menu('plugins').add_item(cmd)
tb = UI::Toolbar.new('SayHiTB')
tb.add_item(cmd)
tb.show
The small_icon= method is used to identify the icon file for the command's small icon.
command = command.small_icon = path
path - a path to the small icon.
command - the Command object
toolbar = UI::Toolbar.new "Test"# This toolbar tool simply displays Hello World on the screen when clickedcmd = UI::Command.new($tStrings.GetString("Tester")) { helloWorld }cmd.small_icon = "ToolPencilSmall.png"cmd.large_icon = "ToolPencilLarge.png"toolbar = toolbar.add_item cmdtoolbar.show
The status_bar_text= method is used to set the status bar text for the command.
command = command.status_bar_text= "text"
"text" - the text that will
appear on the status bar when the cursor is over the command's menu item
command - the Command object
toolbar = UI::Toolbar.new "Test"# This toolbar tool simply displays Hello World on the screen when clickedcmd = UI::Command.new($tStrings.GetString("Tester")) { helloWorld }cmd.small_icon = "ToolPencilSmall.png"cmd.large_icon = "ToolPencilLarge.png"cmd.status_bar_text = $tStrings.GetString("Testing the toolbars class")toolbar = toolbar.add_item cmdtoolbar.show
The tooltip= method is used to set the tooltip for the command's icon.
command = command.tooltip= "tooltip"
"tooltip" - the text that appears
when the cursor is over the command's icons
command - a Command object
toolbar = UI::Toolbar.new "Test"# This toolbar tool simply displays Hello World on the screen when clickedcmd = UI::Command.new($tStrings.GetString("Tester")) { helloWorld }cmd.small_icon = "ToolPencilSmall.png"cmd.large_icon = "ToolPencilLarge.png"cmd.tooltip = $tStrings.GetString("Test Toolbars")toolbar = toolbar.add_item cmdtoolbar.show
|
SketchUp Ruby API Reference: Command class |
© Google Inc. 2007 sketchup.google.com |