Skip to content

Instantly share code, notes, and snippets.

@JBou
Created July 15, 2015 15:42
Show Gist options
  • Save JBou/c31f25d3abcc5d2f9623 to your computer and use it in GitHub Desktop.
Save JBou/c31f25d3abcc5d2f9623 to your computer and use it in GitHub Desktop.
#This script was created by Adam Beazley for public use and may be edited.
#http://www.abeazleydesign.com
#Directions
#Just click in the Import Materials button in the plugins menue and type in the location of all of you image files.
#This script will create a material and name it the same name as the image file and then use that file as the texture.
#all textures will come in at a standard scale and must be edited later
#after all materials and textures have been imported into the model, simply add them to your library
#you can then save the library as a .skm library file through sketchup.
#have fun!!!
#
### v1.1 TIG tweaks 29/12/05 ###
#-----------------------------------------------------------------------------
require 'sketchup.rb'
require 'SKMtools.rb'
require 'fileutils'
#-----------------------------------------------------------------------------
def materialimporter2
model= Sketchup.active_model
materials= model.materials
model.start_operation ("Import Materials 2") ###undo - see commit at end
pwd= Dir.getwd.split("/").join+"\\" ### fix for SU
dry = UI.select_directory(title: "Image Import Folder", directory: pwd)
return nil if not dry
dryexpo = UI.select_directory(title: "SKM Export Folder", directory: pwd)
return nil if not dryexpo
cwd= Dir.chdir(dry)
images= Dir["**/*.{jpg,png,tif,bmp,gif,tga,epx}"]### for all supported image file types
for image in images
imgname = File.basename(image, ".*")
#imgname= image.split(".")[0..-2].join(".") ### removes .jpg etc from end
mat= materials.add imgname
mat.texture = image
#mat.export_skm(dryexpo)
currentimgfolder = File.dirname(image)
currentimgfolder.sub! dry, ''
currentimgfolder = currentimgfolder.gsub(/[^A-Za-z0-9_\/-]/, "_")
expoFolder = File.join(File.join(dryexpo.split("\\")), currentimgfolder)
#expoFolder = expoFolder.gsub(/[^A-Za-z0-9_-]/, "_")
FileUtils.mkdir_p expoFolder
mat.export_skm(expoFolder)
mat.delete()
end#for image###
model.commit_operation ###undo all if needed
end#def###
if(not file_loaded?("massmaterialimporter2.rb"))
menu=UI.menu("Plugins")
menu.add_separator
menu.add_item("Import Materials 2") { materialimporter2 }
end
#-----------------------------------------------------------------------------
file_loaded("massmaterialimporter2.rb")
#
def encode_ascii content
array_utf8 = content.unpack('U*')
array_enc = []
array_utf8.each do |num|
if num <= 0x7F
array_enc << num
else
# Numeric entity (&#nnnn;); shard by Stefan Scholl
array_enc.concat "&\##{num};".unpack('C*')
end
end
array_enc.pack('C*')
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment