• Login
sketchucation logo sketchucation
  • Login
πŸ€‘ 30% Off | Artisan 2 on sale until April 30th Buy Now

[Plugin] Import ALL from Folder

Scheduled Pinned Locked Moved Plugins
77 Posts 20 Posters 65.2k Views
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.
  • T Offline
    TIG Moderator
    last edited by 30 Nov 2012, 10:20

    @mattao987 said:

    ...I'd like to add an optionnal STAGE in your script.
    Once a file is imported, i'd like to create a new layer named by reference to the file name with a suffix.
    Let's say Wonka_Niv1
    Then, Group all the freshly imported items on this new layer.
    Then proceed to the next file...

    What file type are you importing?
    SKP and Others need to be treated differently...
    Obviously none of this 'Layering' stuff will ever work with imported 'Images' !!

    For non-SKP files:
    Provided there is at least one object already in the receiving-SKP, then all imported formats [other than a SKP] will already import as a component named after the file - e.g. "Wonka_Niv1.dwg".
    So after line#84:
    model.import(file,false)
    add these lines:
    unless File.extname(list[0]).downcase==".skp" ins=model.definitions[File.basename(file)].instances[0] ins.layer=model.layers.add(File.basename(file, ".*")) end#if
    Note: this uses the imported files 'basename' [e.g. "Wonka_Niv1"], to use the full name with say its '.dwg. suffix use ...add(File.basename(file)) instead

    For SKP imports you will need to edit another part of the code:
    after line#107:
    ins=model.active_entities.add_instance(defn,tr)
    add this:
    ins.layer=model.layers.add(name)
    This uses the imported SKP's name, without any '.skp' suffix [e.g. "Wonka_Niv1"] - but if you want to add one, then change ...add(name) to ...add(File.basename(file))

    This should do what you want... πŸ˜„

    TIG

    1 Reply Last reply Reply Quote 0
    • M Offline
      mattao987
      last edited by 5 Dec 2012, 01:40

      I encounter some errors at the script loading ( sketchup launch time )

      Loading File import_from_folder.rb
      /Library/Application Support/Google SketchUp 8/SketchUp/Plugins/import_from_folder.rb:89: parse error, unexpected '}', expecting kEND
      }
      ^
      /Library/Application Support/Google SketchUp 8/SketchUp/Plugins/import_from_folder.rb:124: parse error, unexpected kEND, expecting '}'
      end#def import_from_folder
      ^
      /Library/Application Support/Google SketchUp 8/SketchUp/Plugins/import_from_folder.rb:134: parse error, unexpected $, expecting '}'

      I've tried a BBedit editing and I suspect some bad editing error. ( I am not a programmer as you can see )

      I've tried to edit the code after sketchup launch and it works one time but only one.

      Could you help?


      import_from_folder.rb

      1 Reply Last reply Reply Quote 0
      • M Offline
        mattao987
        last edited by 5 Dec 2012, 01:51

        Maybe I could use this commandm=Sketchup.active_model;m.start_operation('c');m.active_entities.each{|e|next unless e.is_a?(Sketchup::ComponentInstance);n=e.definition.name;l=m.layers.add(n);e.layer=l};m.commit_operation

        1 Reply Last reply Reply Quote 0
        • T Offline
          TIG Moderator
          last edited by 5 Dec 2012, 10:09

          @mattao987 said:

          Maybe I could use this commandm=Sketchup.active_model;m.start_operation('c');m.active_entities.each{|e|next unless e.is_a?(Sketchup::ComponentInstance);n=e.definition.name;l=m.layers.add(n);e.layer=l};m.commit_operation
          BUT that only puts component-instances in the active_entities context onto layers named after their definitions. πŸ˜•
          The original .rb file in the first post in the thread works just fine.
          I can see you have changed some of it in your example...
          Why?
          I'm not going to look farther into it as I don't understand what you are attempting to do...
          What are you trying to do differently, when compared to the original code ?
          Obviously you have messed up your version that you you attached, it's broken around line#89 πŸ˜’
          πŸ˜•

          TIG

          1 Reply Last reply Reply Quote 0
          • D Offline
            driven
            last edited by 5 Jan 2013, 00:44

            @tig said:

            Why?
            I'm not going to look farther into it as I don't understand what you are attempting to do...

            hi Tig,
            I think he's on a mac, as I just tried to run it and got similar errors.
            As I only needed one folder of images I pulled the bits out and line fed Ruby Console, to ascertain what worked, oddly it was failing at every return and worked when they were removed? is it a 1.8.5 ruby issue? I cobbled the bits that worked in a new file and ran it fine, if you want to see it I can PM...

            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
            • M Offline
              mattao987
              last edited by 5 Jan 2013, 01:02

              Sorry for this long absence, ( a long serie of "bugs" in my working life )

              I've just tried the editing of the code with BBEdit cos it was not working on my mac.

              My goal is to achieve a fast import of files exported from VectorWorks through the DWG plug-in.
              I got a very good answer with your script but I hoped to get it one step beyond

              (Please pardon me my bad english)

              1 Reply Last reply Reply Quote 0
              • D Offline
                driven
                last edited by 5 Jan 2013, 01:11

                hi mattao987

                fill in your profile so everyone knows your on a mac, we are a minority group here...

                I didn't need much of it, but splitting out the explicit returns made the bits I needed work, I also de-modularised it for a one off run.

                If you go through and gat the basics to fully work, I'd suggest PM'ing TIG your working version of the basic script, then talk about extra's...

                Even the initial error reports may help see what's going wrong on mac.

                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
                • D Offline
                  driven
                  last edited by 5 Jan 2013, 01:15

                  @Tig

                  I just tested using ruby 1.8.7 and it worked fine

                  editand now it works with 1.8.5............how peculiar

                  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
                  • M Offline
                    mattao987
                    last edited by 5 Jan 2013, 01:18

                    I will try to update my ruby asap.

                    1 Reply Last reply Reply Quote 0
                    • D Offline
                      driven
                      last edited by 5 Jan 2013, 01:24

                      @mattao987 said:

                      I will try to update my ruby asap.

                      it's just a button click with the new [soon to be released plugin]
                      look up the mac ruby thread, I haven't got it handy,
                      or PM me
                      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
                      • P Offline
                        pmagans
                        last edited by 16 Jan 2014, 15:06

                        TIG,
                        Do you know of any .stl batch importers? I have found two .stl importers but nothing with the batch capabilities.
                        Thanks

                        1 Reply Last reply Reply Quote 0
                        • T Offline
                          TIG Moderator
                          last edited by 16 Jan 2014, 17:37

                          @pmangans

                          This tool 'Import ALL from Folder' will batch import STL files - if you have the SketchUp STL import/export tool installed: http://extensions.sketchup.com/en/content/sketchup-stl

                          However because of that importer's coding I think it is not hash-able - so it will use the last options set in its dialog - and you must answer 'Yes' when prompted for each STL file in imports as that can't be switched off...

                          Get 'Import ALL from Folder' v1.3 here: http://sketchucation.com/pluginstore?pln=import_from_folder

                          TIG

                          1 Reply Last reply Reply Quote 0
                          • P Offline
                            pmagans
                            last edited by 16 Jan 2014, 20:25

                            Thanks TIG that worked

                            1 Reply Last reply Reply Quote 0
                            • B Offline
                              bitslapped
                              last edited by 10 Jun 2014, 22:50

                              I love this plugin. I think a nice addition would be an option to import onto a grid so components are easier to manage.
                              Thanks TIG

                              1 Reply Last reply Reply Quote 0
                              • T Offline
                                TIG Moderator
                                last edited by 11 Jun 2014, 08:15

                                @bitslapped said:

                                I love this plugin. I think a nice addition would be an option to import onto a grid so components are easier to manage.
                                Thanks TIG
                                Try http://sketchucation.com/pluginstore?pln=components_grid
                                This arranges installed components on a user chosen 'grid'...

                                TIG

                                1 Reply Last reply Reply Quote 0
                                • Y Offline
                                  YoungOSG
                                  last edited by 15 Jan 2015, 06:24

                                  @tig said:

                                  @mattao987 said:

                                  ...I'd like to add an optionnal STAGE in your script.
                                  Once a file is imported, i'd like to create a new layer named by reference to the file name with a suffix.
                                  Let's say Wonka_Niv1
                                  Then, Group all the freshly imported items on this new layer.
                                  Then proceed to the next file...

                                  What file type are you importing?
                                  SKP and Others need to be treated differently...
                                  Obviously none of this 'Layering' stuff will ever work with imported 'Images' !!

                                  For non-SKP files:
                                  Provided there is at least one object already in the receiving-SKP, then all imported formats [other than a SKP] will already import as a component named after the file - e.g. "Wonka_Niv1.dwg".
                                  So after line#84:
                                  model.import(file,false)
                                  add these lines:
                                  unless File.extname(list[0]).downcase==".skp" ins=model.definitions[File.basename(file)].instances[0] ins.layer=model.layers.add(File.basename(file, ".*")) end#if
                                  Note: this uses the imported files 'basename' [e.g. "Wonka_Niv1"], to use the full name with say its '.dwg. suffix use ...add(File.basename(file)) instead

                                  For SKP imports you will need to edit another part of the code:
                                  after line#107:
                                  ins=model.active_entities.add_instance(defn,tr)
                                  add this:
                                  ins.layer=model.layers.add(name)
                                  This uses the imported SKP's name, without any '.skp' suffix [e.g. "Wonka_Niv1"] - but if you want to add one, then change ...add(name) to ...add(File.basename(file))

                                  This should do what you want... πŸ˜„

                                  after i use this plugins to add ade files,i can not see them!
                                  i can not understand why.
                                  any helps?

                                  1 Reply Last reply Reply Quote 0
                                  • T Offline
                                    TIG Moderator
                                    last edited by 15 Jan 2015, 17:17

                                    You said 'ade', I guess you really meant '.DAE' ?
                                    They should import OK.
                                    Any error messages in the Ruby Console when try it ??

                                    TIG

                                    1 Reply Last reply Reply Quote 0
                                    • Y Offline
                                      YoungOSG
                                      last edited by 18 Jan 2015, 13:47

                                      @tig said:

                                      You said 'ade', I guess you really meant '.DAE' ?
                                      They should import OK.
                                      Any error messages in the Ruby Console when try it ??

                                      Yes! I mean *.dae files.
                                      I use your script.and add purge_unsed,export.
                                      However i need to handle thousands of files.Sketchup always crashes after export few files.
                                      I really don't know how to fix it.
                                      any helps?


                                      purge_multi_dae2 (2).rb

                                      1 Reply Last reply Reply Quote 0
                                      • D Offline
                                        driven
                                        last edited by 18 Jan 2015, 14:32

                                        I only use mac, but...

                                        you could, save each file to 'Trash', close it, then open a new for the next import?

                                        SU should then be starting fresh each time and you don't need to erase any entities?

                                        just a thought, I use the idea in a script...
                                        this is the an extract for Trash on a mac...

                                        def revert
                                          trash_copy = (File.expand_path("~/.Trash/" + "." + @orig.title + ".skp")).dup.freeze
                                          @orig.save(trash_copy)
                                          Sketchup.send_action("closeDocument;")
                                          Sketchup.send_action("newDocument;")
                                        end
                                        

                                        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
                                        • T Offline
                                          TIG Moderator
                                          last edited by 19 Jan 2015, 11:12

                                          @Young

                                          You code is overly complicated.
                                          It also has some odd working practices... πŸ˜•

                                          I am sure I have answered this same query elsewhere...
                                          See the @yuyuwhy posts...
                                          Is it you, but with a different user-name ??
                                          http://sketchucation.com/forums/viewtopic.php?p=554042#p554042

                                          This thread explains how to setup an empty model SKP - the order of purging IS important - yours is wrong !
                                          Do that BEFORE importing anything.

                                          It also suggests a sensible approach to the subsequent import, purge and export of each DAE in turn.
                                          If you enclose those actions within a ' model.start_operation(...)' block, BUT afterward each you ' model.abort_operation' it [NOT the usual ' model.commit_operation' it] then the imported data is simply forgotten, but the export is safe because the DAE file is now outside of the SKP's control... So there is no need to purge between each import/export at all.

                                          Recast your code thus...
                                          Make the host SKP empty.
                                          Process the list of DAE files in turn.
                                          Use a model.start_operation(...) block around each iterate step.
                                          Remember to use the model.abort_operation to undo the import etc, but leave the export intact.
                                          You should end up with an empty SKP and all of the DAE files processed.

                                          Incidentally, your code only works in v2015 as the UI folder selector is new in that version's API.

                                          TIG

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

                                          Advertisement