sketchucation logo sketchucation
    • Login
    ℹ️ Licensed Extensions | FredoBatch, ElevationProfile, FredoSketch, LayOps, MatSim and Pic2Shape will require license from Sept 1st More Info

    [Plugin] Export Batch DAE

    Scheduled Pinned Locked Moved Plugins
    29 Posts 7 Posters 44.8k Views 7 Watching
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • D Offline
      driven
      last edited by

      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

      learn from the mistakes of others, you may not live long enough to make them all yourself...

      1 Reply Last reply Reply Quote 0
      • RoidsanR Offline
        Roidsan
        last edited by

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

        Everything's alright now, the photographer's here.

        1 Reply Last reply Reply Quote 0
        • TIGT Offline
          TIG Moderator
          last edited by

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

          TIG

          1 Reply Last reply Reply Quote 0
          • RoidsanR Offline
            Roidsan
            last edited by

            Thank you TIG for the answer AND your patience. 😄

            Everything's alright now, the photographer's here.

            1 Reply Last reply Reply Quote 0
            • TIGT Offline
              TIG Moderator
              last edited by

              😄 That's OK, I suffer fools gladly, as I am one on occasion!

              TIG

              1 Reply Last reply Reply Quote 0
              • D Offline
                davdup
                last edited by

                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

                1 Reply Last reply Reply Quote 0
                • TIGT Offline
                  TIG Moderator
                  last edited by

                  @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 !
                  🤓

                  TIG

                  1 Reply Last reply Reply Quote 0
                  • D Offline
                    davdup
                    last edited by

                    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

                    1 Reply Last reply Reply Quote 0
                    • TIGT Offline
                      TIG Moderator
                      last edited by

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

                      TIG

                      1 Reply Last reply Reply Quote 0
                      • D Offline
                        davdup
                        last edited by

                        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


                        Batch OBJ export script

                        1 Reply Last reply Reply Quote 0
                        • R Offline
                          riberholt
                          last edited by

                          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.

                          1 Reply Last reply Reply Quote 0
                          • TIGT Offline
                            TIG Moderator
                            last edited by

                            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 &nbsp;</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

                            1 Reply Last reply Reply Quote 0
                            • G Offline
                              glro
                              last edited by

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

                              1 Reply Last reply Reply Quote 0
                              • TIGT Offline
                                TIG Moderator
                                last edited by

                                Of course... with the right code... 😒

                                TIG

                                1 Reply Last reply Reply Quote 0
                                • TIGT Offline
                                  TIG Moderator
                                  last edited by

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

                                  TIG

                                  1 Reply Last reply Reply Quote 0
                                  • R Offline
                                    RasmusL
                                    last edited by

                                    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.

                                    1 Reply Last reply Reply Quote 0
                                    • R Offline
                                      RasmusL
                                      last edited by

                                      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.

                                      1 Reply Last reply Reply Quote 0
                                      • TIGT Offline
                                        TIG Moderator
                                        last edited by

                                        @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 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... 😒
                                        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... 😲

                                        TIG

                                        1 Reply Last reply Reply Quote 0
                                        • G Offline
                                          glro
                                          last edited by

                                          @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

                                          1 Reply Last reply Reply Quote 0
                                          • TIGT Offline
                                            TIG Moderator
                                            last edited by

                                            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

                                            1 Reply Last reply Reply Quote 0
                                            • 1
                                            • 2
                                            • 2 / 2
                                            • First post
                                              Last post
                                            Buy SketchPlus
                                            Buy SUbD
                                            Buy WrapR
                                            Buy eBook
                                            Buy Modelur
                                            Buy Vertex Tools
                                            Buy SketchCuisine
                                            Buy FormFonts

                                            Advertisement