Skip to content

Instantly share code, notes, and snippets.

@madeindjs
Last active November 30, 2016 13:16
Show Gist options
  • Save madeindjs/1261115632cf3b8eee3704e89d5eedb2 to your computer and use it in GitHub Desktop.
Save madeindjs/1261115632cf3b8eee3704e89d5eedb2 to your computer and use it in GitHub Desktop.
convert all files from the given directory into the given format
# convert all files from the given directory into the given format
#
# @note For SketchUp Pro 7.1+, valid extensions include dae, kmz, 3ds, dwg, dxf, fbx, obj, wrl, and xsi. SketchUp Free only supports dae and kmz. (see http://www.sketchup.com/intl/en/developer/docs/ourdoc/model#export)
#
# @param src_path [String] as path were sketchup files are stored
# @param dest_path [String] as output path after convertion
# @param export_format [String] as output format
def convert_sketchup_files src_path, dest_path, export_format
format_available = %w(dae kmz 3ds dwg dxf fbx obj wrl xsi pdf)
if format_available.include? export_format
# loop on each files on directory
Dir.foreach(src_path) do |file|
# open the file only if it's a sketchup file
if File.extname(file) == '.skp' and Sketchup.open_file File.join(src_path, file)
# create the export filename
basename = File.basename file, '.skp'
file_dest = File.join dest_path, "#{basename}.dwg"
if Sketchup.active_model.export file_dest
puts '[*] %s saved as .%s' % [basename, export_format ]
else
puts '[ ] %s not saved as .%s' % [basename, export_format ]
end
else
puts "[ ] can't open %s" % File.join(src_path, file)
end
end# next file
else
puts ".%s is not supported" % export_format
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment