# 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 beepTest status = UI.beep if (status) UI.messagebox status else UI.messagebox status end end def inputBoxTest prompts = ["Width", "Height", "Depth"] values = [6, 5, 4] results = inputbox prompts, values, "Test" end def getMenuTest draw_menu = UI.menu("Draw") if (draw_menu) UI.messagebox "Success" else UI.messagebox "Failure" end # UI.menu throws an exception, so I cannot test for failure by checking # the return value. begin invalid_menu = UI.menu("InvalidMenu") rescue UI.messagebox $!.message end #if (invalid_menu) # UI.messagebox "Success" #else # UI.messagebox "Failure" #end end def messageBoxTest # Bug: messagebox default title is "Validity Check" if no title is given keypress = UI.messagebox "Testing with Just a String" UI.messagebox keypress UI.messagebox "Testing with a String and Type", MB_MULTILINE UI.messagebox "Testing with a String, Type, and Title", MB_MULTILINE, "Test" keypress = UI.messagebox "Testing MB_OKCANCEL", MB_OKCANCEL UI.messagebox keypress keypress = UI.messagebox "Testing MB_YESNOCANCEL", MB_YESNOCANCEL UI.messagebox keypress UI.messagebox "Testing MB_YESNO", MB_YESNO keypress = UI.messagebox "Testing MB_RETRYCANCEL", MB_RETRYCANCEL # Can test the return value for the button typed. 1=OK, 2=CANCEL, 4=RETRY # 6=YES, 7=NO UI.messagebox keypress keypress = UI.messagebox "Testing MB_ABORTRETRYIGNORE", MB_ABORTRETRYIGNORE UI.messagebox keypress end def openURLTest status = UI.openURL("http://www.sketchup.com") if (status) UI.messagebox status else UI.messagebox "Failure" end end def openPanelTest #begin # status = UI.openpanel "Open Image File", "c:\Program Files\@Last Software\Sketchup 5\Plugins\", "Shapes.jpg" #rescue #UI.messagebox $!.message #end end def savePanelTest status = UI.savepanel if (status) UI.messagebox status else UI.messagebox "Failure" end end def playSoundTest begin pSound = UI.play_sound "mediadiscussion.wav" rescue UI.messagebox $!.message end end def startTimerTest id = UI.start_timer(10) {UI.beep} if (id) UI.messagebox id else UI.messagebox "Failure" end end def stopTimerTest id = UI.start_timer(10) {UI.beep} if (id) UI.messagebox id else UI.messagebox "Failure" end UI.stop_timer id UI.messagebox "Stopped" end def toolbarUITest toolbar = UI::Toolbar.new "Test" toolbar = UI.toolbar "Test" if (toolbar) UI.messagebox toolbar else UI.messagebox "Failure" end end if( not file_loaded?("uitests.rb") ) # This will add a separator to the menu, but only once add_separator_to_menu("Plugins") # To add an item to a menu, you identify the menu, and then # provide a title to display and a block to execute. In this case, # the block just calls the create_box function plugins_menu = UI.menu("Plugins") UITest_menu = plugins_menu.add_submenu("UI Tests") UITest_menu.add_item("UI.beep") { beepTest } UITest_menu.add_item("UI.inputbox") { inputBoxTest } UITest_menu.add_item("UI.getmenu") { getMenuTest } UITest_menu.add_item("UI.messagebox") { messageBoxTest } UITest_menu.add_item("UI.openURL") { openURLTest } UITest_menu.add_item("UI.openpanel") { openPanelTest } UITest_menu.add_item("UI.savepanel") { savePanelTest } UITest_menu.add_item("UI.play_sound") { playSoundTest } UITest_menu.add_item("UI.start_timer") { startTimerTest } UITest_menu.add_item("UI.stop_timer") {stopTimerTest } UITest_menu.add_item("UI.toolbar") {toolbarUITest} end #----------------------------------------------------------------------------- file_loaded("uitests.rb")