# 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' #----------------------------------------------------------------------------- # Apparently the interpreter doesn't complain when you try to invoke a method # in a class that doesn't exist because I originally named it SketchUp.active_model # Another issue is sometimes you will get an error in a part of the code that you know is fine # The thing to do, in this case, is to check that all of your end markers are in the # appropriate place. # Begin tests for the Sketchup class def activeModelTest model = Sketchup.active_model if (model) UI.messagebox "Success" else UI.messagebox "Failure" end end def findSupportFileTest help_file = Sketchup.find_support_file "index.html", "Ruby/Docs/" if (help_file) UI.messagebox help_file UI.openURL "file://" + help_file else UI.messagebox "Failure" end end # A unit of angular measure in which the angle of an entire circle is 2\pi radians. # There are therefore 360 degrees per 2\i radians, equal to 180^\circ/\pi or 57.29577951/radian. # A right angle is \pi/2 radians. def formatAngleTest angle = Sketchup.format_angle 10 if (angle) UI.messagebox angle else UI.messagebox "Failure" end end def formatAreaTest area = Sketchup.format_area 10 if (area) UI.messagebox area else UI.messagebox "Failure" end end def formatDegreesTest degrees = Sketchup.format_degrees 10 if (degrees) UI.messagebox degrees else UI.messagebox "Failure" end end def formatLengthTest length = Sketchup.format_length 10 if (length) UI.messagebox length else UI.messagebox "Failure" end end def getLocaleSketchupTest locale = Sketchup.get_locale if (locale) UI.messagebox locale else UI.messagebox "Failure" end end def getShortcutsSketchupTest sc = Sketchup.get_shortcuts if (sc) UI.messagebox sc else UI.messagebox "Failure" end end def loadSketchUpTest end def openSketchUpTest end def parseLengthTest length = Sketchup.parse_length "200" if (length) UI.messagebox length else UI.messagebox "Failure" end end # Used to retrieve the string associated with an entry within the specified section in the # application's registry or .INI file. Must pass it a section within the registry or .INI, # an entry within that section, and a default value if the value isn't found. def readDefaultTest Sketchup.write_default "Test", "TesterName", "Jon Dormody" value = Sketchup.read_default "Test", "TesterName" , "JonUtah" if (value) UI.messagebox value else UI.messagebox "Failure" end end def requireSketchUpTest end # Sends a message to the message queue associated with the thread that created the # specific window and returns without waiting for the thread to process the # message. Valid messsages in SketchUp are: # showRubyPanel:, viewBack:, viewBottom:, viewFront:, viewIso:, viewLeft:, viewRight:, viewTop: # viewPserspective:, viewShowAxes:, viewShowHidden:, viewZoomExtents:, viewZoomToSelection:, viewUndo: # selectOrbitTool:, selectPositionCameraTool:, selectDollyTool:, selectTurnTool:, selectWalkTool: # selectZoomTool:, selectFieldOfViewTool:, selectZoomWindowTool:, pageAdd:, pageDelete:, pageUpdate: # pageNext:, pagePrevious:, renderWireframe:, renderHiddenLine:, renderMonochrome:, renderShaded: # renderTextures:, selectArcTool:, selectAxisTool:, selectCircleTool:, selectEraseTool:, selectFreehandTool: # selectLineTool:, selectMeasureTool:, selectMoveTool:, selectOffsetTool:, selectPaintTool:, selectPolygonTool: # selectProtractorTool:, selectPushPullTool:, selectRectangleTool:, selectRotateTool:, selectScaleTool: # selectSectionPlaneTool:, selectTextTool:, selectDimensionTool:, selectExtrudeTool:, selectSelectionTool: # editUndo:, editRedo:, editHide:, editUnhide:, fixNonPlanarFaces: # Returns a boolean true if success or false if failure. def sendActionTest result=Sketchup.send_action("selectMoveTool:") if (result) UI.messagebox result UI.messagebox "Success" else UI.messagebox "Failure" end end def setStatusTextTest UI.messagebox "Clearing the Status Line" Sketchup.set_status_text UI.messagebox "Setting the text in the Prompt Panel of the Status Line" Sketchup.set_status_text "This is a Test" UI.messagebox "Setting the text at a specific location: The VCB Label" Sketchup.set_status_text "Test:", SB_VCB_LABEL end def undoSketchUpTest end # Returns 4.0153 def versionTest version = Sketchup.version if (version) UI.messagebox version else UI.messagebox "Failure" end end # Returns 4.0.153 as 400153 def versionNumberTest version = Sketchup.version_number if (version) UI.messagebox version else UI.messagebox "Failure" end end # Must run this test before running the read test. There is no way to remove # a value from the registry using the SketchUp Ruby API. def writeDefaultTest value = Sketchup.write_default "Test", "TesterName", "Jon Dormody" if (value) UI.messagebox "Value Written:" + value else UI.messagebox "Failure" end end if( not file_loaded?("sketchuptests.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") SUTest_menu = plugins_menu.add_submenu("SketchUp Tests") SUTest_menu.add_item("Sketchup.active_model") { activeModelTest } SUTest_menu.add_item("Sketchup.find_support_file") { findSupportFileTest } SUTest_menu.add_item("Sketchup.format_angle") { formatAngleTest } SUTest_menu.add_item("Sketchup.format_area") { formatAreaTest } SUTest_menu.add_item("Sketchup.format_degrees") { formatDegreesTest } SUTest_menu.add_item("Sketchup.format_length") { formatLengthTest } SUTest_menu.add_item("Sketchup.get_locale") { getLocaleSketchupTest } SUTest_menu.add_item("Sketchup.get_shortcuts") { getShortcutsSketchupTest } SUTest_menu.add_item("Sketchup.load") { loadSketchUpTest } SUTest_menu.add_item("Sketchup.open_file") { openFileSketchUpTest } SUTest_menu.add_item("Sketchup.parse_length") { parseLengthTest } SUTest_menu.add_item("Sketchup.read_default") { readDefaultTest } SUTest_menu.add_item("Sketchup.require") { requireSketchUpTest } SUTest_menu.add_item("Sketchup.send_action") { sendActionTest } SUTest_menu.add_item("Sketchup.set_status_text") { setStatusTextTest } SUTest_menu.add_item("Sketchup.undo") { undoSketchUpTest } SUTest_menu.add_item("Sketchup.version") { versionTest } SUTest_menu.add_item("Sketchup.version_number") { versionNumberTest } SUTest_menu.add_item("Sketchup.write_default") { writeDefaultTest } end #----------------------------------------------------------------------------- file_loaded("sketchuptests.rb")