[Plugin] Export Batch DAE
-
Copyright (c) TIG 2011-2014
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.
Name:
ExportBatchDAE.rb
Usage:
Sketchup Menu > File > Export Batch DAE...
Answer the options dialog, then OK.
[Note that a 'usual' set of 'options' shown - adjust as desired]
Select one SKP from a folder of SKPs to be exported, then OK.
All SKPs in that folder are opened, exported as DAE [using the given
settings] and then closed. You might be prompted to save a SKP - answer
'No'. If the original SKP was unsaved the last exported SKP remains
open, otherwise the original SKP's window is restored.
All exported DAE files are found in a [new] subfolder in the selected
folder called 'DAEs' - there might also be subfolders made to contain
associated texture files, each named after its DAE.
Any preexisting DAE files will be overwritten without a warning.
Donations:
PayPal.com info @ revitrev.org Version:
1.0 20110809 First issue.
1.1 20131228 Future-proofed.
http://sketchucation.com/resources/pluginstore?pln=ExportBatchDAE -
hi TIG,
just did a mac test over lunch...
I made a folder called 'importDAEs_from' and dropped a selection of .skp's in...
started SU and chose batch export...
a new sub-folder named DAE was made, it contains the .dae's and a materials folder for one of the .skps contains a .jpgso all went well.
as a note, the original SKP was unsaved and SU shut down on completion of exports.
is it possible to preserve groups or maybe convert them to components on-mass prior to export?
john
-
Hi, driven...
If you have any SKP where you want to make all of its groups into component-instances prior to export use this one-liner, or insert the code just after '
Sketchup.open_file(skp)
' in the batch exporter script...Sketchup.active_model.definitions.each{|d|(d.instances.each{|i|i.to_component})if d.group?}
-
hi Tig that works, as well...
however it seems that using this 'disappears' the toolbars , but I thought it was Thomas's new tool, so didn't mention it earlier.
I then thought it was
Sketchup.send_action('terminate:') that was doing it , but just tested that on it's own and it doesn't.so must be something else in the script, both versions...
john
-
There is nothing in this script or thomthom's that should [could] cause this to happen...they are both well wrapped in their own methods and don't mess with any other classes/methods/methods that I know of...
What other scripts do you have loading ?? -
hi TIG,
I've got a reasonably stable set of well organised plugins that don't interfere with my launcher app.if I add anything ropey it usually interferes with my launch so I eliminate or fix it first.
most of the rubies are in additional folders and I just load them when I need to use them, I have some of yours, thomthom's, jim's and chris's and fredo's in the wild and these are the floating toolbars that I use all the time.
I also have some of the oldtimers like weld, rotated rectangle, mesh additions, etc...
the only installed ones that ever play up are EEby Vector to Obj [if I extrude bezier curves] and a couple of webDialog issues with the latest version of Safari.
it really does appear to be something to do with this, so I'll clarify what happens.
if I open SU and 'save' the empty file, and then use 'Export Batch DAE' everything works and on completion SU stays open, if I then quit SU and reopen I still have my 'floating toolbars'
if I don't save the initial file, on completion SU closes itself and when I reopen my 'floating toolbars' have gone.
my 'custom toolbar' remains intact in both scenarios...
CHANGE OF PLAN
ok, problem still persists... and I also tested without tt_shell...
I don't actually have a current use for this plugin, I'm just mac testing it out of curiosity...
john
-
From your description the code that runs if you didn't have a 'saved' SKP open when you started exporting is
Sketchup.send_action('terminate:')
On the PC that line closes the window belonging to the last SKP exported.
However, if the open SKP had been saved before exporting then it's reopened again, so the last SKP exported window closes.
Perhaps the 'terminate:
' code on a MAC behaves differently from a PC...
Change the line
Sketchup.send_action('terminate:')
to
###Sketchup.send_action('terminate:') UI.messagebox('Please close this last SKP window manually!')
The last exported SKP stays open and you are asked to close it yourself
Retry - it shouldn't then affect your toolbars ??Of course the simple trick to avoid this is to open one of the SKPs in the folder of SKPs you want to batch-export, then the folder selection jumps to that folder as the start point and you select any SKP + OK and you are off and running - the originally opened SKP is reopened on completion...
-
tried that,
toolbars remain intact, but none of the windows are closed by SU, you need to manually close them all.
one of the reasons for my interest is your use of Sketchup.send_action('terminate:')
as I was hoping to use it in something else.it seems quite stable when used on it's own from Ruby Console with 'saved', 'un-saved', 'individual' or 'multiple' skp's.
I currently use an shell script killall SketchUp in a couple of things, but have to run a separate app to send it [as SU won't] and I also keep looking for a less harsh way to instantly 'close all' when a process is taking far longer then the results warrant.
john
-
Quick Newbie question -Can't find an answer with multiple searches, so I guess I have to ask, what does DEA refer to?
-
@roidsan said:
Quick Newbie question -Can't find an answer with multiple searches, so I guess I have to ask, what does DEA refer to?
"DEA" is an unknown file type!
I suspect you meant "DAE" [as in this exporter] which is the Collada file format [developed by Sony Computer Entertainment and the Khronos Group]; it is short for "digital asset exchange", it's an 'xml' format; it's now widely used for 3d data transfer - similar to DXF - it is also very similar to Google Earth's own .kmz file-format etc. -
Thank you TIG for the answer AND your patience.
-
That's OK, I suffer fools gladly, as I am one on occasion!
-
Hi TIG,
Thanks a lot for all your plugins!
I managed to adapt this one to be able to batch export skps into OBJ files, but I still have to clic "OK" on the "OBJ Export Results" popup to move to the next file, which is a little bit annoying for a batch process!
And of course I don't know how to code this to do it automatically... could you or anyone else help me? Thanks!David
-
@davdup said:
Hi TIG,
Thanks a lot for all your plugins!
I managed to adapt this one to be able to batch export skps into OBJ files, but I still have to click "OK" on the "OBJ Export Results" popup to move to the next file, which is a little bit annoying for a batch process!
And of course I don't know how to code this to do it automatically... could you or anyone else help me? Thanks!David
IF you had posted your script we might be better able to see where it needs fixing !
However, using my super-powers of clairvoyance I suspect that you need code along these lines...
model.export(objpath, **false**)
which might help - the second argument controls the appearance of the prompt in all exports other than DAE, which can take an 'options-hash' - OBJ can't take a 'hash' [it uses Sketchup's 'current-settings'] - so if you pass a 'hash' the exporter sees it as just 'true', and so it pops up the report each time !
-
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?
Advertisement