Convert .skp to .obj together

I have 7000 sketchup files and I’ve to convert all of them to .obj
format. It is not smart approach to export each file one by one so is
there any way to convert all of them at once?

Write an RB script which opens every SKP in a selected folder in turn and then runs the exporter on it to make the OBJ version…
Here’s a quick v2015 example:

full_path_to_the_folder = UI.select_directory(title: "Select SKP folder...")
return unless full_path_to_the_folder
    File.extname(e).downcase == ".skp"
    Sketchup.active_model.export(File.join(full_path_to_the_folder, skp.gsub(/[Ss][Kk][Pp]$/, "obj")), false)

Typed from memory, so it’s untested so check for typos…

should likely be (if you want the obj files in the same folder:)


ie: full_path_to_the_folder is a var reference, not a string.

The new filename using string interpolation instead of a gsub call is just my preference as it doesn’t make Ruby create a Regexp object. (Perhaps the regular expression way might be faster, IF the Regexp object was created outside the loop, instead of recreated during each iteration.)

Ruby’s flexibility is so cool.

P.S.: TIG’s example is meant to be wrapped in a method (hence the return statement.)

Right again.
As I said it was untested - a silly typo.
I’ve edited the original to avoid confusion too…

Here’s a fuller/better version that actually works !
Save text into a file named TIG-Export.rb
Use Notepad++ [PC] or TextWrangler [MAC] to ensure it is encoded as UTF8-without_BOM
Usage: In Ruby Console,"obj")
The passed argument let’s you export to any available file-format…

# encoding: UTF-8
### v2015
module TIG
    module Export
            dir = UI.select_directory(title: "Select folder of SKPs...")
            return unless dir
  !("\\", "/")
            puts "#{dir}\n"
            pwd = Dir.pwd
            Dir.entries(dir).select{|e| e =~ /[.]skp$/ }.each{|skp|
                    nam = skp.gsub(/skp$/, typ)
                    puts "#{skp} >>> #{nam}"
                    Sketchup.active_model.export(nam, false)
            puts "\nDone."
1 Like

Thank u for your valuable comments. Where do i need to place this “TIG-Export.rb” file? Do I only need to write“obj”) in SU Ruby Console?

place it in your Plugins folder Sketchup.find_support_file("Plugins")
or use load "add/your/path/to/the.rb" in ‘Ruby Console’
or zip the file, change the .zip to .rbz and ‘Preferences’ > ‘Extensions’ > ‘Add Extension’
then use"obj")

I placed the file in plugins folder now I’m getting this error on sketchup startup.

Error Loading File TIG-Export.rb
Error: #<SyntaxError: C:/Users/manish/AppData/Roaming/SketchUp/SketchUp 2014/SketchUp/Plugins/TIG-Export.rb:15: syntax error, unexpected ‘,’, expecting ‘}’
Sketchup.active_model.export(nam), false)


C:/Users/manish/AppData/Roaming/SketchUp/SketchUp 2014/SketchUp/Plugins/TIG-Export.rb:19: syntax error, unexpected keyword_end, expecting ‘}’


Sorry, a typo by me.
I have removed the extra ) in the posted code.
Recopy if from above and paste over the RB file’s contents.
It should then work !

Shall I replace Sketchup.active_model.export(nam), false) with Sketchup.active_model.export(nam, false) ?

That is the corrected typo.
Well spotted.

Try 1:“obj”)

Error: #NameError: uninitialized constant TIG::Exporter

:in `' -e:1:in `eval' Nil

Try 2“obj”)

Error: #NoMethodError: undefined method select_directory' for UI:Module C:/Users/manish/AppData/Roaming/SketchUp/SketchUp 2014/SketchUp/Plugins/TIG-Export.rb:6:in new’

:in `' -e:1:in `eval' Nil

You must restart SketchUp to load the file, or… force it to load via the Ruby Console:

load "TIG-Export.rb"

select_directory() is only SketchUp 2015 or later.

[quote=“DanRathbun, post:13, topic:10539”]

You can replace

            dir = UI.select_directory(title: "Select folder of SKPs...")
            return unless dir


            dir = UI.openpanel("Select SKP file in folder...","*.skp","SketchUp Files (*.SKP)|*.skp;||")
            return unless dir
            dir = File.dirname(dir)

It works great… Thanks to all of u…


Reading Object file : examples\zidle_2529df1273423fa7a524f6bfc21eae12.obj
% Alias OBJ Model File
% Exported from SketchUp, (c) 2000-2012 Trimble Navigation Limited
% File units = centimeters
Reading Material file : examples\idle_2529df1273423fa7a524f6bfc21eae12.mtl

I’m getting error reading obj beacuse the name of mtl file associated with obj is truncates first letter [idle_2529df1273423fa7a524f6bfc21eae12.mtl] while exporting. What shall I do?

Hello, i was looking for the same solution to changing multiple files formats from .skp to .obj, what i have tried but couldnt get it work.

I downloaded this code : TIG-Export.rb
I loaded this code via sketchup ruby console, and when i load it it says “TRUE” and nothing happends
I tried installing it as .rbz extension but when i installed it, nothing appeared in extension menu. So please, can someone explain me step by step how to convert these files? and how to use this code?

Where did you get that rb file from - above ?

A lone RB file goes in your Plugins folder and is loaded as SketchUp starts.
If you manually load it from the Ruby Console it’s available then, even if it’s not in the Plugins folder.
The instructions are usually provided with a script on its download page.
There are lots of instructions and comments above…
This one is undoubtedly an old simple script - not and Extension - perhaps it is run from the Ruby Console ? [like it says]

From what you say it’s not going to do what you want anyway ?
You want a ‘batch’ tool that takes all of the SKPs in a selected folder and makes OBJs…
Here’s an example RB - Pro only - TIG-ExportBatchOBJ.rb (3.1 KB)
It adds an OBJ Batch Exporter to the File menu, so it’s easier to use on a folder…

If possible, convert all "\" backslashes in pathstrings to "/" forward slashes. (The backslashes and the following characters are read as escape sequences. So it is seeing "\z" as an escape sequence.)

newpath ="\\",'/')

TIG-Export.rb (829 Bytes)

Keep the name as it is. It is the same provided by TIG sir.