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

    Save out all individual components

    Scheduled Pinned Locked Moved SketchUp Discussions
    sketchup
    15 Posts 5 Posters 2.8k Views 5 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.
    • E Offline
      ericschimel
      last edited by

      Does anyone know of a way that you can mass save all the components in a model?

      I've got a very large model that is made entirely of components that I need to save out as separate files over and over again... I know I can right click each one and click "Save As" but we're talking about 100s of files. I'd also have to do it each time I update the main model.

      It would be nice to be able to filter the files based on their names too...

      I've look around for different plugins and I haven't found anything just yet....

      -Eric
      http://plugin.sketchthis.net
      Sketchup Kitchen Design Plugin
      Custom Models

      1 Reply Last reply Reply Quote 0
      • BoxB Offline
        Box
        last edited by

        I'm not sure if I am reading your question too simplistically but:
        You can save a whole model full of components as a collection from within the component browser. This will place all the components into a folder as individual .skp files. Nested components are done as one file tho, but you can always open that file and save a collection from there etc
        There are several plugins for linking and updating components which can be used to manage the components in external files, first one that springs to mind is Inteloide's Component Manager http://sketchucation.com/forums/viewtopic.php?p=505544#p505544
        Tig has one also. http://sketchucation.com/forums/viewtopic.php?p=46367#p46367

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

          As Box says...
          The 'Save_As' occurs as a context-menu option if you select a component-instance in the model OR its icon in the Components-Browser Model-pane...
          The pop-out drop-down menu in the Components-Browser offers 'Save as a local collection...' - in the resulting dialog simply navigate and specify a folder [probably best to make a new one]... and then all of the component definitions in the model should get exported as individual SKP files in that folder, in one step...

          If you have any Groups which you'd like making into Components before saving the collection, then this one liner will do that...

          Sketchup.active_model.definitions.each{|d| d.instances.each{|i|i.to_component} if d.group?}
          

          TIG

          1 Reply Last reply Reply Quote 0
          • E Offline
            ericschimel
            last edited by

            That sort of works... It looks like it only gets components at the top level though.... What I'd love to be able to do is have something that saves out all components in sub folders with the name of their parent component...

            -Eric
            http://plugin.sketchthis.net
            Sketchup Kitchen Design Plugin
            Custom Models

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

              This saves all components - including nested ones - into a folder in the Model's folder.
              Components that are entirely nested are put into folders with the parent's name.
              Unacceptable characters are gsub'd as _0, if this makes duplicate names they are next'd as ..._1 etc
              The code needs to go into a .rb that loads from Plugins.
              It runs by TIG.save_all_components in the Ruby Console but of course you can easily add a menu/toolbar...

              module TIG
              	def TIG.save_all_components()
              		m=Sketchup.active_model
              		p=m.path.tr("\\","/")
              		unless p.empty? # i.e. NOT Untitled/unsaved
              		  f=File.join(File.dirname(p), "#{m.title}_Components")
              		  begin
              			Dir.mkdir(f)
              		  rescue
              		  end
              		  ns={}
              		  m.definitions.each{|d|
              			next if d.group? || d.image?
              			n=d.name.gsub(/[\<\>\{\}\/\\\;\?\"]/, '_0')
              			while ns[n]==true
              			  n.next!
              			end
              			if d.hidden?
              			  d.instances.each{|i|
              				  s=File.join(f, i.parent.name.gsub(/[\<\>\{\}\/\\\;\?\"]/, '_0'))
              				  begin
              					Dir.mkdir(s)
              				  rescue
              				  end
              				  c=File.join(s, n)
              				  begin
              				  d.save_as(c)
              				  ns[n]=true
              				  puts "Saved #{c}"
              				rescue
              				  ns[n]=false
              				  puts "Failed to save #{c}"
              				end
              			  }
              			else # in model
              				c=File.join(f, n)
              				begin
              				  d.save_as(c)
              				  ns[n]=true
              				  puts "Saved #{c}"
              				rescue
              				  ns[n]=false
              				  puts "Failed to save #{c}"
              				end
              			end
              			
              		  }
              		end#if
              		return
              	end
              end
              

              TIG

              1 Reply Last reply Reply Quote 0
              • BoxB Offline
                Box
                last edited by

                Tig it goes without saying but sometimes needs saying, the code you rattle off between breaths is simply gobsmacking.

                1 Reply Last reply Reply Quote 0
                • JQLJ Offline
                  JQL
                  last edited by

                  Wouldn't this be useful to turn into a plugin on the plugin store. Maybe if Rich would walk on by?

                  www.casca.pt
                  Visit us on facebook!

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

                    I'll make it into a new Plugin πŸ€“

                    TIG

                    1 Reply Last reply Reply Quote 0
                    • JQLJ Offline
                      JQL
                      last edited by

                      Didn't want to give you any more trouble but... what if this would go inside Xref tools code? πŸ˜•

                      www.casca.pt
                      Visit us on facebook!

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

                        It's now published properly: http://sketchucation.com/forums/viewtopic.php?p=530343#p530343
                        PluginStore: http://sketchucation.com/pluginstore?pln=TIG_save_all_components

                        TIG

                        1 Reply Last reply Reply Quote 0
                        • ludnidL Offline
                          ludnid
                          last edited by

                          @tig said:

                          It's now published properly: http://sketchucation.com/forums/viewtopic.php?p=530343#p530343
                          PluginStore: http://sketchucation.com/pluginstore?pln=TIG_save_all_components

                          Hello TIG,

                          Can you please create a version of this script that executes its function only at the top level? Doesn't have to placed in the plugin store if its too much trouble.

                          Thanks in advance.

                          If you don't ask, the answer will always be no.

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

                            This is more than 7 years old !

                            It in effect does that already.
                            Nested components are saved into a subfolder named after the parent definition ?
                            Just ignore those in subfolders if you only want the parents...
                            Or am I missing something...

                            TIG

                            1 Reply Last reply Reply Quote 0
                            • ludnidL Offline
                              ludnid
                              last edited by

                              @tig said:

                              This is more than 7 years old !

                              It in effect does that already.
                              Nested components are saved into a subfolder named after the parent definition ?
                              Just ignore those in subfolders if you only want the parents...
                              Or am I missing something...

                              It does, just not perfectly.

                              Some of the nested components don't go into sub folders and end up being in the main export. So you have to sort through and delete them. A bit of a nightmare as I was working through a collection of portraits from the warehouse, hence the reason I asked.

                              If you don't ask, the answer will always be no.

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

                                Try this v2.0...
                                It offers a new Y|N option at the start to save each definitions into the main folder = N, or =Y to save any nested definitions into subfolders named after their parent.
                                Then you can choose to ignore those - e.g. those nested inside other components, or those in groups [which you might want to consider keeping ?]


                                TIG_save_all_components_v2.0.rbz

                                TIG

                                1 Reply Last reply Reply Quote 0
                                • ludnidL Offline
                                  ludnid
                                  last edited by

                                  @tig said:

                                  Try this v2.0...
                                  It offers a new Y|N option at the start to save each definitions into the main folder = N, or =Y to save any nested definitions into subfolders named after their parent.
                                  Then you can choose to ignore those - e.g. those nested inside other components, or those in groups [which you might want to consider keeping ?]

                                  My man!! πŸ‘Š

                                  If you don't ask, the answer will always be no.

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

                                  Advertisement