# 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 directionConstructionLineTest model = Sketchup.active_model entities = model.active_entities point1 = Geom::Point3d.new (0,0,0) point2 = Geom::Point3d.new (20,20,20) constline = entities.add_cline point1, point2 vector = constline.direction if (vector) UI.messagebox vector else UI.messagebox "Failure" end end def directionEqualsConstructionLineTest model = Sketchup.active_model entities = model.active_entities point2 = Geom::Point3d.new (20,20,20) vector = Geom::Vector3d.new constline = entities.add_cline point1, point2 vector = constline.direction if (vector) UI.messagebox vector else UI.messagebox "Failure" end newvector = Geom::Vector3d.new 30,30,30 vector = constline.direction=newvector if (vector) UI.messagebox vector else UI.messagebox "Failure" end end def endConstructionLineTest model = Sketchup.active_model entities = model.active_entities point1 = Geom::Point3d.new (0,0,0) point2 = Geom::Point3d.new (20,20,20) constline = entities.add_cline point1, point2 endofline = constline.end if (endofline) UI.messagebox endofline else UI.messagebox "Failure" end end def endEqualsConstructionLineTest model = Sketchup.active_model entities = model.active_entities point1 = Geom::Point3d.new (0,0,0) point2 = Geom::Point3d.new (20,20,20) point3 = Geom::Point3d.new (10,10,10) constline = entities.add_cline point1, point2 endofline = constline.end=nil if (endofline) UI.messagebox endofline else UI.messagebox endofline end end def positionConstructionLineTest model = Sketchup.active_model entities = model.active_entities point1 = Geom::Point3d.new (0,0,0) #point2 = Geom::Point3d.new (20,20,20) vector = Geom::Vector3d.new (10,10,10) constline = entities.add_cline point1, vector # What does this return if it isn't an infinite line? I get 0,0,0 position = constline.position if (position) UI.messagebox position else UI.messagebox "Failure" end end def positionEqualsConstructionLineTest model = Sketchup.active_model entities = model.active_entities point1 = Geom::Point3d.new (0,0,0) point2 = Geom::Point3d.new (20,20,20) point3 = Geom::Point3d.new (0,20,20) constline = entities.add_cline point1, point2 position = constline.position=point3 if (position) UI.messagebox position else UI.messagebox "Failure" end end def reverseConstructionLineTest model = Sketchup.active_model entities = model.active_entities point1 = Geom::Point3d.new (0,0,0) point2 = Geom::Point3d.new (20,20,20) constline = entities.add_cline point1, point2 status = constline.reverse! if (status) UI.messagebox status else UI.messagebox status end end def startConstructionLineTest model = Sketchup.active_model entities = model.active_entities point1 = Geom::Point3d.new (0,0,0) point2 = Geom::Point3d.new (20,20,20) constline = entities.add_cline point1, point2 startofline = constline.start if (startofline) UI.messagebox startofline else UI.messagebox "Failure" end end def startEqualsConstructionLineTest model = Sketchup.active_model entities = model.active_entities point1 = Geom::Point3d.new (0,0,0) point2 = Geom::Point3d.new (20,20,20) point3 = Geom::Point3d.new (5,5,5) constline = entities.add_cline point1, point2 startofline = constline.start=point3 if (startofline) UI.messagebox startofline else UI.messagebox "Failure" end end def stippleConstructionLineTest model = Sketchup.active_model entities = model.active_entities point1 = Geom::Point3d.new (0,0,0) point2 = Geom::Point3d.new (20,20,20) constline = entities.add_cline point1, point2 # Default returns 0 pattern = constline.stipple if (pattern) UI.messagebox pattern else UI.messagebox "Failure" end end def stippleEqualsConstructionLineTest model = Sketchup.active_model entities = model.active_entities point1 = Geom::Point3d.new (0,0,0) point2 = Geom::Point3d.new (20,20,20) constline = entities.add_cline point1, point2 UI.messagebox "Changing stipple" pattern = constline.stipple="__" if (pattern) UI.messagebox pattern else UI.messagebox "Failure" end end if( not file_loaded?("constructionlinetests.rb") ) # This will add a separator to the menu, but only once add_separator_to_menu("Plugins") plugins_menu = UI.menu("Plugins") ConstructionLine_menu = plugins_menu.add_submenu("ConstructionLine Tests") ConstructionLine_menu.add_item("ConstructionLine.direction") { directionConstructionLineTest } ConstructionLine_menu.add_item("ConstructionLine.direction=") { directionEqualsConstructionLineTest } ConstructionLine_menu.add_item("ConstructionLine.end") { endConstructionLineTest } ConstructionLine_menu.add_item("ConstructionLine.end=") { endEqualsConstructionLineTest } ConstructionLine_menu.add_item("ConstructionLine.position") { positionConstructionLineTest } ConstructionLine_menu.add_item("ConstructionLine.position=") { positionEqualsConstructionLineTest } ConstructionLine_menu.add_item("ConstructionLine.reverse!") { reverseConstructionLineTest } ConstructionLine_menu.add_item("ConstructionLine.start") { startConstructionLineTest } ConstructionLine_menu.add_item("ConstructionLine.start=") { startEqualsConstructionLineTest } ConstructionLine_menu.add_item("ConstructionLine.stipple") { stippleConstructionLineTest } ConstructionLine_menu.add_item("ConstructionLine.stipple=") { stippleEqualsConstructionLineTest } end #----------------------------------------------------------------------------- file_loaded("constructionlinetests.rb")