Save out all individual components
-
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....
-
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 -
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?}
-
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...
-
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 byTIG.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 it goes without saying but sometimes needs saying, the code you rattle off between breaths is simply gobsmacking.
-
Wouldn't this be useful to turn into a plugin on the plugin store. Maybe if Rich would walk on by?
-
I'll make it into a new Plugin
-
Didn't want to give you any more trouble but... what if this would go inside Xref tools code?
-
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 said:
It's now published properly: http://sketchucation.com/forums/viewtopic.php?p=530343#p530343
PluginStore: http://sketchucation.com/pluginstore?pln=TIG_save_all_componentsHello 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.
-
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 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.
-
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 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!!
Advertisement