# 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 getMaterialsTest 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 mat = materials[0] if (mat) UI.messagebox mat else UI.messagebox "Failure" end end def addMaterialsTest end def eachMaterialsTest 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 materials.each {| material | UI.messagebox material} end def lengthMaterialsTest 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 length = materials.length if (length) UI.messagebox length else UI.messagebox "Failure" end end if( not file_loaded?("materialstests.rb") ) # This will add a separator to the menu, but only once add_separator_to_menu("Plugins") plugins_menu = UI.menu("Plugins") Materials_menu = plugins_menu.add_submenu("Materials Tests") Materials_menu.add_item("Materials []") { getMaterialsTest } Materials_menu.add_item("Materials.add") { addMaterialsTest } Materials_menu.add_item("Materials.each") { eachMaterialsTest } Materials_menu.add_item("Materials.length") { lengthMaterialsTest } end #----------------------------------------------------------------------------- file_loaded("materialstests.rb")