Save out all individual components
-
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