# 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 lessThanLengthTest length1 = 11 length2 = 12 if length1 < length2 UI.messagebox "Less than" else UI.messagebox "Failure" end end def lessThanEqualsLengthTest length1 = 11 length2 = 12 if 11 <= 12 UI.messagebox "Less than or Equals" else UI.messagebox "Failure" end end def lessThanGreaterThanLengthTest length1 = 11 length2 = 12 if length1 <=> length2 UI.messagebox "Success" else UI.messagebox "Failure" end end def equalsLengthTest length1 = 12 length2 = 12 if length1 == length2 UI.messagebox "Equal" else UI.messagebox "Failure" end end def greaterThanLengthTest length1 = 11 length2 = 12 if length2 > length1 UI.messagebox "Greater Than" else UI.messagebox "Failure" end end def greaterThanEqualsLengthTest length1 = 11 length2 = 12 if length2 >= length1 UI.messagebox "Greater Than or Equal" else UI.messagebox "Failure" end end def inspectLengthTest depth = 100 width = 100 model = Sketchup.active_model entities = model.active_entities pts = [] pts[0] = [0, 0, 0] pts[1] = [width, 0, 0] pts[2] = [width, depth, 0] pts[3] = [0, depth, 0] # Add the face to the entities in the model face = entities.add_face pts length = entities.length str = length.inspect if (str) UI.messagebox str else UI.messagebox "Failure" end end def toFLengthTest depth = 100 width = 100 model = Sketchup.active_model entities = model.active_entities pts = [] pts[0] = [0, 0, 0] pts[1] = [width, 0, 0] pts[2] = [width, depth, 0] pts[3] = [0, depth, 0] # Add the face to the entities in the model face = entities.add_face pts length = entities.length f = length.to_f if (f) UI.messagebox f else UI.messagebox "Failure" end end def toSLengthTest depth = 100 width = 100 model = Sketchup.active_model entities = model.active_entities pts = [] pts[0] = [0, 0, 0] pts[1] = [width, 0, 0] pts[2] = [width, depth, 0] pts[3] = [0, depth, 0] # Add the face to the entities in the model face = entities.add_face pts length = entities.length s = length.to_s if (s) UI.messagebox s else UI.messagebox "Failure" end end if( not file_loaded?("lengthtests.rb") ) # This will add a separator to the menu, but only once add_separator_to_menu("Plugins") plugins_menu = UI.menu("Plugins") Length_menu = plugins_menu.add_submenu("Length Tests") Length_menu.add_item("Length <") { lessThanLengthTest } Length_menu.add_item("Length <=") { lessThanEqualsLengthTest } Length_menu.add_item("Length <=>") { lessThanGreaterThanLengthTest } Length_menu.add_item("Length ==") { equalsLengthTest } Length_menu.add_item("Length >") { greaterThanLengthTest } Length_menu.add_item("Length >=") { greaterThanEqualsLengthTest } Length_menu.add_item("Length.inspect") { inspectLengthTest } Length_menu.add_item("Length.to_f") { toFLengthTest } Length_menu.add_item("Length.to_s") { toSLengthTest } end #----------------------------------------------------------------------------- file_loaded("lengthtests.rb")