# 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 averageColorTextureTest model = Sketchup.active_model materials = model.materials # Adds a material to the "in-use" material pallet. m = materials.add "Joe" begin # Returns nil if not successful, path if successful. Should return a texture object m.texture="c:\\Program Files\\@Last Software\\SketchUp 4\\Materials\\Carpet.jpg" rescue UI.messagebox $!.message end texture = m.texture UI.messagebox texture # Returns a color object average = texture.average_color if (average) UI.messagebox average else UI.messagebox "Failure: No Average Color" end end def filenameTextureTest model = Sketchup.active_model materials = model.materials # Adds a material to the "in-use" material pallet. m = materials.add "Joe" begin # Returns nil if not successful, path if successful. Should return a texture object m.texture="c:\\Program Files\\@Last Software\\SketchUp 4\\Materials\\Carpet.jpg" rescue UI.messagebox $!.message end texture = m.texture UI.messagebox texture filename = texture.filename if (filename) UI.messagebox filename else UI.messagebox "Failure" end end def heightTextureTest model = Sketchup.active_model materials = model.materials # Adds a material to the "in-use" material pallet. m = materials.add "Joe" begin # Returns nil if not successful, path if successful. Should return a texture object m.texture="c:\\Program Files\\@Last Software\\SketchUp 4\\Materials\\Carpet.jpg" rescue UI.messagebox $!.message end texture = m.texture UI.messagebox texture height = texture.height if (height) UI.messagebox height else UI.messagebox "Failure" end end def imageHeightTextureTest model = Sketchup.active_model materials = model.materials # Adds a material to the "in-use" material pallet. m = materials.add "Joe" begin # Returns nil if not successful, path if successful. Should return a texture object m.texture="c:\\Program Files\\@Last Software\\SketchUp 4\\Materials\\Carpet.jpg" rescue UI.messagebox $!.message end texture = m.texture UI.messagebox texture height = texture.image_height if (height) UI.messagebox height else UI.messagebox "Failure" end end def imageWidthTextureTest model = Sketchup.active_model materials = model.materials # Adds a material to the "in-use" material pallet. m = materials.add "Joe" begin # Returns nil if not successful, path if successful. Should return a texture object m.texture="c:\\Program Files\\@Last Software\\SketchUp 4\\Materials\\Carpet.jpg" rescue UI.messagebox $!.message end texture = m.texture UI.messagebox texture width = texture.image_width if (width) UI.messagebox width else UI.messagebox "Failure" end end def sizeEqualsTextureTest model = Sketchup.active_model materials = model.materials # Adds a material to the "in-use" material pallet. m = materials.add "Joe" begin # Returns nil if not successful, path if successful. Should return a texture object m.texture="c:\\Program Files\\@Last Software\\SketchUp 4\\Materials\\Tile-Ceramic.jpg" rescue UI.messagebox $!.message end texture = m.texture UI.messagebox texture # Can give width and height or just one dimension and the other will adjust # Accordingly size = texture.size=5,100 if (size) UI.messagebox size else UI.messagebox "Failure" end end def validTextureTest model = Sketchup.active_model materials = model.materials # Adds a material to the "in-use" material pallet. m = materials.add "Joe" begin # Returns nil if not successful, path if successful. Should return a texture object m.texture="c:\\Program Files\\@Last Software\\SketchUp 4\\Materials\\Carpet.jpg" rescue UI.messagebox $!.message end texture = m.texture UI.messagebox texture status = texture.valid? if (status) UI.messagebox status else UI.messagebox "Failure" end end def widthTextureTest model = Sketchup.active_model materials = model.materials # Adds a material to the "in-use" material pallet. m = materials.add "Joe" begin # Returns nil if not successful, path if successful. Should return a texture object m.texture="c:\\Program Files\\@Last Software\\SketchUp 4\\Materials\\Carpet.jpg" rescue UI.messagebox $!.message end texture = m.texture UI.messagebox texture width = texture.width if (width) UI.messagebox width else UI.messagebox "Failure" end end if( not file_loaded?("texturetests.rb") ) # This will add a separator to the menu, but only once add_separator_to_menu("Plugins") plugins_menu = UI.menu("Plugins") Texture_menu = plugins_menu.add_submenu("Texture Tests") Texture_menu.add_item("Texture.average_color") { averageColorTextureTest } Texture_menu.add_item("Texture.filename") { filenameTextureTest } Texture_menu.add_item("Texture.height") { heightTextureTest } Texture_menu.add_item("Texture.image_height") { imageHeightTextureTest } Texture_menu.add_item("Texture.image_width") { imageWidthTextureTest } Texture_menu.add_item("Texture.size=") { sizeEqualsTextureTest } Texture_menu.add_item("Texture.valid?") { validTextureTest } Texture_menu.add_item("Texture.width") { widthTextureTest } end #----------------------------------------------------------------------------- file_loaded("texturetests.rb") #depth = 100 #width = 100 #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