[Plugin] Export Batch DAE
-
Here is the script!
model.export function already has a second argument... perhaps changing the last two variables (double_precision, vertex_normals) or adding a new one can help?
OBJ batch export script, adapted from TIG's DAE export script
-
You missed my point entirely.
You can't pass an 'options-hash' to the exporter... UNLESS it's exporting a DAE file.
All of your code/dialog about getting settings for the OBJ is wasted.
The OBJ exporter always uses the last used Sketchup OBJ export options.
Your code won't affect those and is a waste of time/effort.
What it does do is pass 'something' other than 'false' to the exporter, which it then interprets as 'true', so the 'report' dialog pops up each time !
The settings in the hash are simply ignored !
Its easier than you've made it - just use
opts=false
it will work without the reports interrupting BUT you need to have the OBJ options set first.
-
Oh I just realized this digging into the Sketchup API reference!
So no hash for exports except DAEs. I simply replaced the "opts" parameter with "False" and everything works fine... You just have to set the OBJ export parameters right before running the script.
Anyway, thanks a lot again! This will save me a lot of clics!I attached the "revised" cleaned up script if anyone needs it!
David
-
I'm looking for a script that will batch convert files from 3ds to dae format using sketchup.
I have found this script in an old thread
#convert skp to obj #every thumb is putted in a created dir with name of related skp model's name #skppath is the residence of skpfiles require 'sketchup.rb' if(not file_loaded?("skp2obj.rb")) plugins_menu = UI.menu("Plugins") plugins_menu.add_item("skp2obj") {file_export} end file_loaded("skp2obj.rb") def file_export #skp file path #beware the end "/" e.g. skppath ="c;\skp" skppath ="C;/Program Files (x86)/Google/Google SketchUp 8/" #open dir and loop all skps dir = Dir.open(skppath) begin dir.each {|x| next if x !~ /\.skp$/i x = "#{x}" sourcefile = skppath+x x = x[0,x.length-4] destdir = skppath + x + "/" destfile = destdir + x +".obj" #mak dir Dir.mkdir(destdir) #open modle file Sketchup.file_new status = Sketchup.open_file sourcefile if (!status) UI.messagebox "error; " + sourcefile end #export obj status = Sketchup.active_model.export destfile if (!status) UI.messagebox "error; " + sourcefile end } ensure dir.close end UI.messagebox "Finished" end and tried to modify it to import and export #convert skp to dae #every thumb is putted in a created dir with name of related skp model's name #skppath is the residence of skpfiles require 'sketchup.rb' if(not file_loaded?("3ds2dae.rb")) plugins_menu = UI.menu("Plugins") plugins_menu.add_item("3ds2dae") {file_export} end file_loaded("3ds2dae.rb") def file_export #skp file path #beware the end "/" e.g. skppath ="i;/skp/skptest/model/error/" skppath ="C;/skp/" #open dir and loop all skps dir = Dir.open(skppath) begin dir.each {|x| next if x !~ /\.skp$/i x = "#{x}" sourcefile = skppath+x x = x[0,x.length-4] destdir = skppath + x + "/" destfile = destdir + x +".dae" #make dir Dir.mkdir(destdir) #open model file Sketchup.file_new status = model.import sourcefile if (!status) UI.messagebox "error; " + sourcefile end #export dae status = Sketchup.active_model.export destfile if (!status) UI.messagebox "error; " + sourcefile end } ensure dir.close end UI.messagebox "Finished" end
But it seems my RubyFU is not strong enough. Any help would be appreciated.
-
I think this will only work on pro..
<span class="syntaxdefault">require </span><span class="syntaxstring">'sketchup.rb'<br /></span><span class="syntaxdefault">module TIG<br />def self</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">makeDAEfrom3DS</span><span class="syntaxkeyword">()<br /></span><span class="syntaxdefault"> model</span><span class="syntaxkeyword">=</span><span class="syntaxdefault">Sketchup</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">active_model<br /> view</span><span class="syntaxkeyword">=</span><span class="syntaxdefault">model</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">active_view<br /> cam</span><span class="syntaxkeyword">=</span><span class="syntaxdefault">view</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">camera<br /> eye</span><span class="syntaxkeyword">=</span><span class="syntaxdefault">cam</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">eye<br /> target</span><span class="syntaxkeyword">=</span><span class="syntaxdefault">cam</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">target<br /> up</span><span class="syntaxkeyword">=</span><span class="syntaxdefault">cam</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">up<br /> import</span><span class="syntaxkeyword">=</span><span class="syntaxdefault">UI</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">openpanel</span><span class="syntaxkeyword">(</span><span class="syntaxstring">"Select 3DS File..."</span><span class="syntaxkeyword">,</span><span class="syntaxdefault"> Dir</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">pwd</span><span class="syntaxkeyword">,</span><span class="syntaxdefault"> </span><span class="syntaxstring">".3ds"</span><span class="syntaxkeyword">)<br /></span><span class="syntaxdefault"> return nil unless import </span><span class="syntaxkeyword">&&</span><span class="syntaxdefault"> File</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">extname</span><span class="syntaxkeyword">(</span><span class="syntaxdefault">import</span><span class="syntaxkeyword">).</span><span class="syntaxdefault">downcase</span><span class="syntaxkeyword">==</span><span class="syntaxstring">".3ds"<br /></span><span class="syntaxdefault"> import</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">tr</span><span class="syntaxkeyword">!(</span><span class="syntaxstring">"\\"</span><span class="syntaxkeyword">,</span><span class="syntaxstring">"/"</span><span class="syntaxkeyword">)<br /></span><span class="syntaxdefault"> dir</span><span class="syntaxkeyword">=</span><span class="syntaxdefault">File</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">dirname</span><span class="syntaxkeyword">(</span><span class="syntaxdefault">import</span><span class="syntaxkeyword">)<br /></span><span class="syntaxdefault"> dae</span><span class="syntaxkeyword">=</span><span class="syntaxdefault">File</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">basename</span><span class="syntaxkeyword">(</span><span class="syntaxdefault">import</span><span class="syntaxkeyword">,</span><span class="syntaxdefault"> </span><span class="syntaxstring">".*"</span><span class="syntaxkeyword">)+</span><span class="syntaxstring">".dae"<br /></span><span class="syntaxdefault"> export</span><span class="syntaxkeyword">=</span><span class="syntaxdefault">File</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">join</span><span class="syntaxkeyword">(</span><span class="syntaxdefault">dir</span><span class="syntaxkeyword">,</span><span class="syntaxdefault"> dae</span><span class="syntaxkeyword">)<br /></span><span class="syntaxdefault"> puts import<br /> puts </span><span class="syntaxstring">"TO"<br /></span><span class="syntaxdefault"> puts export<br /> model</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">start_operation</span><span class="syntaxkeyword">(</span><span class="syntaxstring">"makeDAEfrom3DS"</span><span class="syntaxkeyword">)<br /></span><span class="syntaxdefault"> ents</span><span class="syntaxkeyword">=</span><span class="syntaxdefault">model</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">entities<br /> ents</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">clear</span><span class="syntaxkeyword">!<br /></span><span class="syntaxdefault"> model</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">definitions</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">purge_unused<br /> model</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">materials</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">purge_unused<br /> model</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">layers</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">purge_unused<br /> model</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">styles</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">purge_unused<br /> model</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">import</span><span class="syntaxkeyword">(</span><span class="syntaxdefault">import</span><span class="syntaxkeyword">,</span><span class="syntaxdefault"> false</span><span class="syntaxkeyword">)<br /></span><span class="syntaxdefault"> model</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">select_tool</span><span class="syntaxkeyword">(</span><span class="syntaxdefault">nil</span><span class="syntaxkeyword">)<br /></span><span class="syntaxdefault"> tr</span><span class="syntaxkeyword">=</span><span class="syntaxdefault">Geom</span><span class="syntaxkeyword">;;</span><span class="syntaxdefault">Transformation</span><span class="syntaxkeyword">.new(</span><span class="syntaxdefault"> </span><span class="syntaxkeyword">)<br /></span><span class="syntaxdefault"> model</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">active_entities</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">add_instance</span><span class="syntaxkeyword">(</span><span class="syntaxdefault">model</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">definitions</span><span class="syntaxkeyword">[</span><span class="syntaxdefault">0</span><span class="syntaxkeyword">],</span><span class="syntaxdefault"> tr</span><span class="syntaxkeyword">)<br /></span><span class="syntaxdefault"> model</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">export</span><span class="syntaxkeyword">(</span><span class="syntaxdefault">export</span><span class="syntaxkeyword">,</span><span class="syntaxdefault"> false</span><span class="syntaxkeyword">)<br /></span><span class="syntaxdefault"> Sketchup</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">send_action</span><span class="syntaxkeyword">(</span><span class="syntaxstring">"editUndo;"</span><span class="syntaxkeyword">)<br /></span><span class="syntaxdefault"> Sketchup</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">send_action</span><span class="syntaxkeyword">(</span><span class="syntaxstring">"editUndo;"</span><span class="syntaxkeyword">)<br /></span><span class="syntaxdefault"> Sketchup</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">send_action</span><span class="syntaxkeyword">(</span><span class="syntaxstring">"editUndo;"</span><span class="syntaxkeyword">)<br /></span><span class="syntaxdefault"> view</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">camera</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">set</span><span class="syntaxkeyword">(</span><span class="syntaxdefault">eye</span><span class="syntaxkeyword">,</span><span class="syntaxdefault"> target</span><span class="syntaxkeyword">,</span><span class="syntaxdefault"> up</span><span class="syntaxkeyword">)<br /></span><span class="syntaxdefault"> model</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">abort_operation<br />end</span><span class="syntaxcomment">#method<br /></span><span class="syntaxdefault">end</span><span class="syntaxcomment">#module </span><span class="syntaxdefault"></span>
Usage: open a SKP and in the Ruby Console type [or copy+paste]
TIG.makeDAEfrom3DS
+ <enter>. Choose the 3DS file + OK. The SKP's contents are 'removed temporarily', and the 3DS is then imported, it is then exported as a DAE file with the same location, name etc, but with a .dae suffix, the SKP's contents and view are restored on completion. The current 3DS import and DAE export settings are used. You can expand this to use a custom settings-hash, or process files in a batch form without the dialogs etc... -
@tig said:
...
Select one SKP from a folder of SKPs to be exported, then OK.would it be possible to export all skp files in a folder AND subfolders?
-
Of course... with the right code...
-
@rasmusl said:
Dear TIG
Sorry, I am completely new to this and I am looking for a batch conversion of 3ds to dae.
I see that you have already the batch export from skp to dae and I guess that the below code would do the trick. However I am completly incapable of joining the information into something that works. May I kindly ask you to do this? I will be super grateful if you will help me.Is it possible to modify this script to batch import 3ds files instead of skp and export to dae? (and how?)
Reason for asking is that I have more than 1000 3ds files that I need in 3rd party software and I need to have the sketchup version of dae.
I posted some example code that does [could do] exactly this... it's in another post from earlier today... do a Search...
-
Dear TIG
Sorry, I am completely new to this and I am looking for a batch conversion of 3ds to dae.
I see that you have already the batch export from skp to dae and I guess that the above code would do the trick. However I am completly incapable of joining the information into something that works. May I kindly ask you to do this? I will be super grateful if you will help me.Is it possible to modify this script to batch import 3ds files instead of skp and export to dae? (and how?)
Reason for asking is that I have more than 1000 3ds files that I need in 3rd party software and I need to have the sketchup version of dae.
-
I think it is in this topic, from 4:32 today?
I tried it, but how do I get it to loop through all the 3ds files like a batch.
-
@rasmusl said:
I think it is in this topic, from 4:32 today?
I tried it, but how do I get it to loop through all the 3ds files like a batch.
Get the user to choose one 3DS file in the folder.
Currently the code uses the returned file path.
BUT let's say we have the returned
filepath=UI.openpanel(...)
From that you can find
folder=File.dirname(filepath)
[There's currently no APIUI.getfolder()
method... ]
From the folder you can find all of the 3DS files...
There are several ways, e.g...
files=[] Dir.entries(folder).each{|f|files << File.join(folder,f) if File.extname(f).downcase==".3ds"}
Now we have an array of all 3ds files in that folder...
Each array element is a full path...
Use a 'batch' process like this...
` files.each{|file|ALL OF THE CODE TO IMPORT/EXPORT '3ds file' GOES HERE...
}`
Unless you want to pay to have a properly written script I'll leave it there...
Hint: to process files in subfolders do something similar to the above but this time make a list of all folders in the 'selected' folder, then iterate through the contents of each of those in turn, adding any 3ds files to the array for the ultimate batch processingPlease be wary - I have typed this from memory, so it's untested...
-
@tig said:
Of course... with the right code...
OK... i'll keep working on it then.
My question is linked to ae snapshot plugin, when it is used to collect informations about all skp files on the hard drive, create a thumbnail and a file shortcut in a specified folder.
I adapted Jim FOLTZ's code to open each skp file in a folder, zoom out and save, so when it is saved, aesnapshot creates automatically the thumbnail and the file shortcut
model = Sketchup.active_model # Open model entities = model.entities # All entities in model selection = model.selection # Current selection #choose a file skppath = UI.openpanel "choose a file","*.skp" skppath = File.dirname(skppath) skppath = skppath.tr("\\","/") skppath = skppath + "/" #skppath ="C;/recap_skp/" #open dir and loop all skps dir = Dir.open(skppath) begin dir.each {|x| next if x !~ /\.skp$/i x = "#{x}" sourcefile = skppath+x x = x[0,x.length-4] #prompt between files prompt2 = UI.messagebox("registering #{sourcefile} ?",MB_OKCANCEL) if prompt2 ==2 fail end #open model file Sketchup.file_new status = Sketchup.open_file sourcefile #zoom out view = Sketchup.active_model.active_view new_view = view.zoom_extents #save status = model.save sourcefile } ensure dir.close end UI.messagebox "Finished"
I am not sure about the necessity of the prompt between the files register
-
I expect that the prompt is a device to get the view zoomed before doing the export, otherwise you might find it's exported before the zoom is finished ?
-
@tig said:
I expect that the prompt is a device to get the view zoomed before doing the export, otherwise you might find it's exported before the zoom is finished ?
yes
maybe a timer would be enough, so it would not be necessary to wait and click for each file
-
model.options["PageOptions"]["ShowTransition"] = false
might help...
OR this entire thing as an example ?<span class="syntaxdefault">def scenes2images</span><span class="syntaxkeyword">()<br /></span><span class="syntaxdefault"> model</span><span class="syntaxkeyword">=</span><span class="syntaxdefault">Sketchup</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">active_model<br /> view</span><span class="syntaxkeyword">=</span><span class="syntaxdefault">model</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">active_view<br /> width</span><span class="syntaxkeyword">=</span><span class="syntaxdefault">view</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">vpwidth</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">to_int<br /> height</span><span class="syntaxkeyword">=</span><span class="syntaxdefault">view</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">vpheight</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">to_int<br /></span><span class="syntaxcomment">### you can change the width/height away from the default if you desire<br /></span><span class="syntaxdefault"> pages</span><span class="syntaxkeyword">=</span><span class="syntaxdefault">model</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">pages<br /> pages_times</span><span class="syntaxkeyword">=[]<br /></span><span class="syntaxdefault"> pages</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">each</span><span class="syntaxkeyword">{|</span><span class="syntaxdefault">page</span><span class="syntaxkeyword">|</span><span class="syntaxdefault">pages_times</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">push</span><span class="syntaxkeyword">([</span><span class="syntaxdefault">page</span><span class="syntaxkeyword">,</span><span class="syntaxdefault">page</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">transition_time</span><span class="syntaxkeyword">])<br /></span><span class="syntaxdefault"> page</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">transition_time</span><span class="syntaxkeyword">=</span><span class="syntaxdefault">0.0 </span><span class="syntaxkeyword">}<br /></span><span class="syntaxcomment">### remembers pages' transition times and sets them all to 0<br /></span><span class="syntaxdefault"> filepath</span><span class="syntaxkeyword">=</span><span class="syntaxdefault">File</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">dirname</span><span class="syntaxkeyword">(</span><span class="syntaxdefault">model</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">path</span><span class="syntaxkeyword">)+</span><span class="syntaxstring">"\\"<br /></span><span class="syntaxdefault"> 0</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">upto</span><span class="syntaxkeyword">(</span><span class="syntaxdefault">pages</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">count</span><span class="syntaxkeyword">-</span><span class="syntaxdefault">1</span><span class="syntaxkeyword">)do|</span><span class="syntaxdefault">images</span><span class="syntaxkeyword">|<br /></span><span class="syntaxdefault"> </span><span class="syntaxcomment">### this msgbox pauses and lets each view refresh and the image process...<br /></span><span class="syntaxdefault"> UI</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">messagebox</span><span class="syntaxkeyword">(</span><span class="syntaxstring">"Exporting Image of Scene..."</span><span class="syntaxkeyword">)<br /></span><span class="syntaxdefault"> model</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">active_view</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">write_image</span><span class="syntaxkeyword">(</span><span class="syntaxstring">"#{filepath+pages.selected_page.name}.jpg"</span><span class="syntaxkeyword">,</span><span class="syntaxdefault">width</span><span class="syntaxkeyword">,</span><span class="syntaxdefault">height</span><span class="syntaxkeyword">,</span><span class="syntaxdefault">true</span><span class="syntaxkeyword">)<br /></span><span class="syntaxdefault"> Sketchup</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">send_action</span><span class="syntaxkeyword">(</span><span class="syntaxstring">"pageNext;"</span><span class="syntaxkeyword">)<br /></span><span class="syntaxdefault"> end</span><span class="syntaxcomment">#loop<br />### reset pages' transition times<br /></span><span class="syntaxdefault"> pages_times</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">each</span><span class="syntaxkeyword">{|array|array[</span><span class="syntaxdefault">0</span><span class="syntaxkeyword">].</span><span class="syntaxdefault">transition_time</span><span class="syntaxkeyword">=array[</span><span class="syntaxdefault">1</span><span class="syntaxkeyword">]}<br /></span><span class="syntaxdefault"> UI</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">messagebox</span><span class="syntaxkeyword">(</span><span class="syntaxstring">"Scenes' Image Exporting - Completed."</span><span class="syntaxkeyword">)<br /></span><span class="syntaxdefault">end</span><span class="syntaxcomment">#def<br /> </span><span class="syntaxdefault"></span>
Advertisement