# 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 exportTextures ss = Sketchup.active_model.selection tw = Sketchup.create_texture_writer ss.each do |ent| case ent.typename when "Face" tw.load(ent, true) tw.load(ent, false) when "ComponentInstance" tw.load(ent) when "Group" tw.load(ent) when "Image" tw.load(ent) end end #tw.write_all("C:\\textures", false) ss.each do |ent| case ent.typename when "Face" uvHelp = ent.get_UVHelper(true, true, tw) handle = tw.handle(ent, true) puts "handle = " + handle.to_s #puts "Front Face Path = " + tw.filename(handle).to_s if handle > -1 retval = tw.write(ent, true, "C:\\textures\\A.jpg") retval = (retval == FILE_WRITE_OK) puts "retval="+retval.to_s ent.outer_loop.vertices.each do |vert| uvq = uvHelp.get_front_UVQ(vert.position) puts "u=" + uvq.x.to_s + " v=" + uvq.y.to_s end handle = tw.handle(ent, false) puts "handle = " + handle.to_s #puts "Back Face Path = " + tw.filename(handle).to_s if handle > -1 retval = tw.write(ent, false, "C:\\textures\\B.jpg") retval = (retval == FILE_WRITE_OK) puts "retval="+retval.to_s ent.outer_loop.vertices.each do |vert| uvq = uvHelp.get_back_UVQ(vert.position) puts "u=" + uvq.x.to_s + " v=" + uvq.y.to_s end when "ComponentInstance" handle = tw.handle(ent) puts "ci handle = " + handle.to_s #puts "CI path = " + tw.filename(handle).to_s if handle > -1 retval = tw.write(ent, "C:\\textures\\C.jpg") retval = (retval == FILE_WRITE_OK) puts "retval="+retval.to_s when "Group" handle = tw.handle(ent) puts "group handle = " + handle.to_s #puts "Group path = " + tw.filename(handle).to_s if handle > -1 retval = tw.write(ent, "C:\\textures\\D.jpg") retval = (retval == FILE_WRITE_OK) puts "retval="+retval.to_s when "Image" handle = tw.handle(ent) puts "image handle = " + handle.to_s #puts "Image path = " + tw.filename(handle).to_s if handle > -1 retval = tw.write(ent, "C:\\textures\\E.jpg") retval = (retval == FILE_WRITE_OK) puts "retval="+retval.to_s end end puts "Count=" + tw.length.to_s puts "done" end # Add some menu items to access this if( not file_loaded?("TextureWriter.rb") ) plugins_menu = UI.menu("Plugins") plugins_menu.add_item("Export Textures") { exportTextures } end #----------------------------------------------------------------------------- file_loaded("TextureWriter.rb")