# Copyright 2005, @Last Software, Inc. # This software is provided as an example of using the Ruby interface # to SketchUp. # Permission to use, copy, modify, and distribute this software for # any purpose and without fee is hereby granted, provided that the above # copyright notice appear in all copies. # THIS SOFTWARE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR # IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED # WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. #----------------------------------------------------------------------------- require 'sketchup.rb' #----------------------------------------------------------------------------- def newCommandTest 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 if (cmd) UI.messagebox cmd else "Failure" end end def largeIconEqualsCommandTest toolbar = UI::Toolbar.new "Test" # This toolbar tool simply displays Hello World on the screen when clicked cmd = UI::Command.new($tStrings.GetString("Test")) { helloWorld } cmd.small_icon = "ToolPencilSmall.png" cmd.large_icon = "ToolPencilLarge.png" toolbar = toolbar.add_item cmd toolbar.show if (toolbar) UI.messagebox toolbar else UI.messagebox "Failure" end end def menuTextEqualsCommandTest 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 } cmd = cmd.menu_text = "New String" testmenu.add_item cmd if (cmd) UI.messagebox cmd else "Failure" end end def setValidationProcCommandTest end def smallIconEqualsCommandTest toolbar = UI::Toolbar.new "Test" # This toolbar tool simply displays Hello World on the screen when clicked cmd = UI::Command.new($tStrings.GetString("Tester")) { helloWorld } cmd.small_icon = "ToolPencilSmall.png" cmd.large_icon = "ToolPencilLarge.png" toolbar = toolbar.add_item cmd toolbar.show if (toolbar) UI.messagebox toolbar else UI.messagebox "Failure" end end def statusBarTextEqualsCommandTest toolbar = UI::Toolbar.new "Test" # This toolbar tool simply displays Hello World on the screen when clicked cmd = 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 cmd toolbar.show if (toolbar) UI.messagebox toolbar else UI.messagebox "Failure" end end def tooltipEqualsCommandTest toolbar = UI::Toolbar.new "Test" # This toolbar tool simply displays Hello World on the screen when clicked cmd = 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 cmd toolbar.show if (toolbar) UI.messagebox toolbar else UI.messagebox "Failure" end end def helloWorld UI.messagebox "Hello World" end if( not file_loaded?("commandtests.rb") ) # This will add a separator to the menu, but only once add_separator_to_menu("Plugins") plugins_menu = UI.menu("Plugins") CommandTest_menu = plugins_menu.add_submenu("Command Tests") CommandTest_menu.add_item("Command.new") { newCommandTest } CommandTest_menu.add_item("Command.large_icon=") { largeIconEqualsCommandTest } CommandTest_menu.add_item("Command.menu_text=") { menuTextEqualsCommandTest } CommandTest_menu.add_item("Command.set_validation_proc") { setValidationProcCommandTest } CommandTest_menu.add_item("Command.small_icon=") { smallIconEqualsCommandTest } CommandTest_menu.add_item("Command.status_bar_text=") { statusBarTextEqualsCommandTest } CommandTest_menu.add_item("Command.tooltip=") { tooltipEqualsCommandTest } end #----------------------------------------------------------------------------- file_loaded("commandtests.rb")