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

      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 Offline
        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 Offline
              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 Offline
                  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 Offline
                      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 Offline
                          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