# 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 explodeImageTest model = Sketchup.active_model path = Sketchup.find_support_file "Shapes.jpg", "Plugins/" pt = Geom::Point3d.new entities = model.active_entities image = entities.add_image path, pt, 300 entitiesarray = image.explode if (entitiesarray) UI.messagebox entitiesarray else UI.messagebox "Failure" end end def heightImageTest model = Sketchup.active_model path = Sketchup.find_support_file "Shapes.jpg", "Plugins/" pt = Geom::Point3d.new entities = model.active_entities image = entities.add_image path, pt, 300 height = image.height if (height) UI.messagebox height else UI.messagebox "Failure" end end def heightEqualsImageTest model = Sketchup.active_model path = Sketchup.find_support_file "Shapes.jpg", "Plugins/" pt = Geom::Point3d.new entities = model.active_entities image = entities.add_image path, pt, 300 UI.messagebox "Before adjustment" height = image.height=400 if (height) UI.messagebox height else UI.messagebox "Failure" end end def normalImageTest model = Sketchup.active_model path = Sketchup.find_support_file "Shapes.jpg", "Plugins/" pt = Geom::Point3d.new entities = model.active_entities image = entities.add_image path, pt, 300 vector = image.normal if (vector) UI.messagebox vector else UI.messagebox "Failure" end end def originImageTest model = Sketchup.active_model path = Sketchup.find_support_file "Shapes.jpg", "Plugins/" pt = Geom::Point3d.new entities = model.active_entities image = entities.add_image path, pt, 300 origin = image.origin if (origin) UI.messagebox origin else UI.messagebox "Failure" end end def originEqualsImageTest model = Sketchup.active_model path = Sketchup.find_support_file "Shapes.jpg", "Plugins/" pt = Geom::Point3d.new pt2 = Geom::Point3d.new 100,100,100 entities = model.active_entities image = entities.add_image path, pt, 300 UI.messagebox "Before Move" origin = image.origin=pt2 if (origin) UI.messagebox origin else UI.messagebox "Failure" end end def pathImageTest model = Sketchup.active_model path = Sketchup.find_support_file "Shapes.jpg", "Plugins/" pt = Geom::Point3d.new entities = model.active_entities image = entities.add_image path, pt, 300 path = image.path if (path) UI.messagebox path else UI.messagebox "Failure" end end def pixelHeightImageTest model = Sketchup.active_model path = Sketchup.find_support_file "Shapes.jpg", "Plugins/" pt = Geom::Point3d.new entities = model.active_entities image = entities.add_image path, pt, 300 pixelheight = image.pixelheight if (pixelheight) UI.messagebox pixelheight else UI.messagebox "Failure" end end def pixelWidthImageTest model = Sketchup.active_model path = Sketchup.find_support_file "Shapes.jpg", "Plugins/" pt = Geom::Point3d.new entities = model.active_entities image = entities.add_image path, pt, 300 pixelwidth = image.pixelwidth if (pixelwidth) UI.messagebox pixelwidth else UI.messagebox "Failure" end end def sizeEqualsImageTest model = Sketchup.active_model path = Sketchup.find_support_file "Shapes.jpg", "Plugins/" pt = Geom::Point3d.new entities = model.active_entities image = entities.add_image path, pt, 300 UI.messagebox "Before Resize" size = image.size= 500,500 if (size) UI.messagebox size else UI.messagebox "Failure" end end def transformImageTest model = Sketchup.active_model path = Sketchup.find_support_file "Shapes.jpg", "Plugins/" point = Geom::Point3d.new 100,100,100 t = Geom::Transformation.new point pt = Geom::Point3d.new entities = model.active_entities image = entities.add_image path, pt, 300 UI.messagebox "Before Move" image = image.transform! t if (image) UI.messagebox image else UI.messagebox "Failure" end end def widthImageTest model = Sketchup.active_model path = Sketchup.find_support_file "Shapes.jpg", "Plugins/" pt = Geom::Point3d.new entities = model.active_entities image = entities.add_image path, pt, 300 width = image.width if (width) UI.messagebox width else UI.messagebox "Failure" end end def widthEqualsImageTest model = Sketchup.active_model path = Sketchup.find_support_file "Shapes.jpg", "Plugins/" pt = Geom::Point3d.new entities = model.active_entities image = entities.add_image path, pt, 300 UI.messagebox "Before adjustment" width = image.width=400 if (width) UI.messagebox width else UI.messagebox "Failure" end end def zrotationImageTest model = Sketchup.active_model path = Sketchup.find_support_file "Shapes.jpg", "Plugins/" pt = Geom::Point3d.new entities = model.active_entities image = entities.add_image path, pt, 300 z = image.zrotation if (z) UI.messagebox z else UI.messagebox "Failure" end end if( not file_loaded?("imagetests.rb") ) # This will add a separator to the menu, but only once add_separator_to_menu("Plugins") plugins_menu = UI.menu("Plugins") Image_menu = plugins_menu.add_submenu("Image Tests") Image_menu.add_item("Image.explode") { explodeImageTest } Image_menu.add_item("Image.height") { heightImageTest } Image_menu.add_item("Image.height=") { heightEqualsImageTest } Image_menu.add_item("Image.normal") { normalImageTest } Image_menu.add_item("Image.origin") { originImageTest } Image_menu.add_item("Image.origin=") { originEqualsImageTest } Image_menu.add_item("Image.path") { pathImageTest } Image_menu.add_item("Image.pixelheight") { pixelHeightImageTest } Image_menu.add_item("Image.pixelwidth") { pixelWidthImageTest } Image_menu.add_item("Image.size=") { sizeEqualsImageTest } Image_menu.add_item("Image.transform!") { transformImageTest } Image_menu.add_item("Image.width") { widthImageTest } Image_menu.add_item("Image.width=") { widthEqualsImageTest } Image_menu.add_item("Image.zrotation") { zrotationImageTest } end #----------------------------------------------------------------------------- file_loaded("imagetests.rb")