[Plugin] Export Batch DAE

[Plugin] Export Batch DAE

Postby TIG » Tue Aug 09, 2011 11:07 am

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.

Download

0
TIG
User avatar
TIG 
Global Moderator
 

Re: [Plugin] Export Batch DAE v1.0 20110809

Postby driven » Tue Aug 09, 2011 2:09 pm

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 .jpg

so 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
0
learn from the mistakes of others, you may not live long enough to make them all yourself...

driven 
PluginStore Author
PluginStore Author
 

Re: [Plugin] Export Batch DAE v1.0 20110809

Postby TIG » Tue Aug 09, 2011 4:27 pm

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...
Code: Select all
Sketchup.active_model.definitions.each{|d|(d.instances.each{|i|i.to_component})if d.group?}
:D :ugeek:
0
TIG
User avatar
TIG 
Global Moderator
 

Re: [Plugin] Export Batch DAE v1.0 20110809

Postby driven » Tue Aug 09, 2011 9:47 pm

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
0
learn from the mistakes of others, you may not live long enough to make them all yourself...

driven 
PluginStore Author
PluginStore Author
 

Re: [Plugin] Export Batch DAE v1.0 20110809

Postby TIG » Tue Aug 09, 2011 10:14 pm

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 ??
0
TIG
User avatar
TIG 
Global Moderator
 

Re: [Plugin] Export Batch DAE v1.0 20110809

Postby driven » Wed Aug 10, 2011 1:22 am

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
parked plugins.png


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
0
learn from the mistakes of others, you may not live long enough to make them all yourself...

driven 
PluginStore Author
PluginStore Author
 

Re: [Plugin] Export Batch DAE v1.0 20110809

Postby TIG » Wed Aug 10, 2011 10:02 am

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...
0
TIG
User avatar
TIG 
Global Moderator
 

Re: [Plugin] Export Batch DAE v1.0 20110809

Postby driven » Wed Aug 10, 2011 12:59 pm

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
0
learn from the mistakes of others, you may not live long enough to make them all yourself...

driven 
PluginStore Author
PluginStore Author
 

Re: [Plugin] Export Batch DAE v1.0 20110809

Postby Roidsan » Wed Aug 10, 2011 3:29 pm

Quick Newbie question :knockout: -Can't find an answer with multiple searches, so I guess I have to ask, what does DEA refer to?
0
Everything's alright now, the photographer's here.
User avatar
Roidsan 
Premium Member
Premium Member
 

Re: [Plugin] Export Batch DAE v1.0 20110809

Postby TIG » Wed Aug 10, 2011 4:42 pm

Roidsan wrote:Quick Newbie question :knockout: -Can't find an answer with multiple searches, so I guess I have to ask, what does DEA refer to?

:roll: "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.
0
TIG
User avatar
TIG 
Global Moderator
 

Re: [Plugin] Export Batch DAE v1.0 20110809

Postby Roidsan » Wed Aug 10, 2011 7:58 pm

Thank you TIG for the answer AND your patience. :D
0
Everything's alright now, the photographer's here.
User avatar
Roidsan 
Premium Member
Premium Member
 

Re: [Plugin] Export Batch DAE v1.0 20110809

Postby TIG » Wed Aug 10, 2011 8:04 pm

:D That's OK, I suffer fools gladly, as I am one on occasion!
0
TIG
User avatar
TIG 
Global Moderator
 

Re: [Plugin] Export Batch DAE v1.0 20110809

Postby davdup » Fri Jan 06, 2012 10:45 am

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
0

davdup 
 

Re: [Plugin] Export Batch DAE v1.0 20110809

Postby TIG » Fri Jan 06, 2012 10:52 am

davdup wrote: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 !
:ugeek:
0
TIG
User avatar
TIG 
Global Moderator
 

Re: [Plugin] Export Batch DAE v1.0 20110809

Postby davdup » Fri Jan 06, 2012 11:04 am

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?
0

davdup 
 

Re: [Plugin] Export Batch DAE v1.0 20110809

Postby TIG » Fri Jan 06, 2012 11:14 am

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.
:roll:
0
TIG
User avatar
TIG 
Global Moderator
 

Re: [Plugin] Export Batch DAE v1.0 20110809

Postby davdup » Fri Jan 06, 2012 11:27 am

Oh I just realized this digging into the Sketchup API reference! :oops:
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
0

davdup 
 

Re: [Plugin] Export Batch DAE v1.0 20110809

Postby riberholt » Thu Oct 25, 2012 3:06 pm

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
Code: Select all
#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.
0

riberholt 
 

Re: [Plugin] Export Batch DAE v1.0 20110809

Postby TIG » Thu Oct 25, 2012 4:23 pm

I think this will only work on pro..
Code: Select all
require 'sketchup.rb'
module TIG
def self
.makeDAEfrom3DS()
  model=Sketchup.active_model
  view
=model.active_view
  cam
=view.camera
  eye
=cam.eye
  target
=cam.target
  up
=cam.up
  import
=UI.openpanel("Select 3DS File...", Dir.pwd, ".3ds")
  return nil unless import && File.extname(import).downcase==".3ds"
  import.tr!("\\","/")
  dir=File.dirname(import)
  dae=File.basename(import, ".*")+".dae"
  export=File.join(dir, dae)
  puts import
  puts 
"TO"
  puts export
 model
.start_operation("makeDAEfrom3DS")
  ents=model.entities
  ents
.clear!
  model.definitions.purge_unused
  model
.materials.purge_unused
  model
.layers.purge_unused
  model
.styles.purge_unused
  model
.import(import, false)
  model.select_tool(nil)
  tr=Geom::Transformation.new( )
  model.active_entities.add_instance(model.definitions[0], tr)
  model.export(export, false)
  Sketchup.send_action("editUndo:")
  Sketchup.send_action("editUndo:")
  Sketchup.send_action("editUndo:")
  view.camera.set(eye, target, up)
 model.abort_operation
end
#method
end#module  
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...
0
TIG
User avatar
TIG 
Global Moderator
 

Re: [Plugin] Export Batch DAE v1.0 20110809

Postby glro » Thu Oct 25, 2012 10:15 pm

TIG wrote:...
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?
0

glro 
 

Re: [Plugin] Export Batch DAE v1.0 20110809

Postby TIG » Thu Oct 25, 2012 10:24 pm

Of course... with the right code... :roll:
0
TIG
User avatar
TIG 
Global Moderator
 

Re: [Plugin] Export Batch DAE v1.0 20110809

Postby RasmusL » Thu Oct 25, 2012 10:45 pm

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.
0
Last edited by RasmusL on Thu Oct 25, 2012 10:51 pm, edited 1 time in total.

RasmusL 
 

Re: [Plugin] Export Batch DAE v1.0 20110809

Postby TIG » Thu Oct 25, 2012 10:50 pm

RasmusL wrote: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...
0
TIG
User avatar
TIG 
Global Moderator
 

Re: [Plugin] Export Batch DAE v1.0 20110809

Postby RasmusL » Thu Oct 25, 2012 11:05 pm

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.
0

RasmusL 
 

Re: [Plugin] Export Batch DAE v1.0 20110809

Postby TIG » Fri Oct 26, 2012 12:12 am

RasmusL wrote: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 API UI.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... :roll:
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 processing ;)

Please be wary - I have typed this from memory, so it's untested... :shock:
0
TIG
User avatar
TIG 
Global Moderator
 

Re: [Plugin] Export Batch DAE v1.0 20110809

Postby glro » Fri Oct 26, 2012 9:48 am

TIG wrote:Of course... with the right code... :roll:


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

Code: Select all
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
0

glro 
 

Re: [Plugin] Export Batch DAE v1.0 20110809

Postby TIG » Fri Oct 26, 2012 10:15 am

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 ?
0
TIG
User avatar
TIG 
Global Moderator
 

Re: [Plugin] Export Batch DAE v1.0 20110809

Postby glro » Fri Oct 26, 2012 10:49 am

TIG wrote: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
0

glro 
 

Re: [Plugin] Export Batch DAE v1.0 20110809

Postby TIG » Fri Oct 26, 2012 11:05 am

model.options["PageOptions"]["ShowTransition"] = false
might help...
OR this entire thing as an example ?
Code: Select all
def scenes2images()
  model=Sketchup.active_model
  view
=model.active_view
  width
=view.vpwidth.to_int
  height
=view.vpheight.to_int
### you can change the width/height away from the default if you desire
  pages=model.pages
  pages_times
=[]
  pages.each{|page|pages_times.push([page,page.transition_time])
    page.transition_time=0.0 }
### remembers pages' transition times and sets them all to 0
  filepath=File.dirname(model.path)+"\\"
  0.upto(pages.count-1)do|images|
    ### this msgbox pauses and lets each view refresh and the image process...
    UI.messagebox("Exporting Image of Scene...")
    model.active_view.write_image("#{filepath+pages.selected_page.name}.jpg",width,height,true)
    Sketchup.send_action("pageNext:")
  end#loop
### reset pages' transition times
  pages_times.each{|array|array[0].transition_time=array[1]}
  UI.messagebox("Scenes' Image Exporting - Completed.")
end#def
 
0
TIG
User avatar
TIG 
Global Moderator
 

SketchUcation One-Liner Adverts

by Ad Machine » 5 minutes ago



Ad Machine 
Robot
 



 

Return to Plugins

Who is online

Users browsing this forum: davililla, fineautosys, fish96, lodovico, micione and 17 guests

Visit our sponsors: