[REQ] Export selected groups/comps to separate skp files
-
Is there a plugin that lets you select one or more groups or components and export them separately as skp to a specific directory? I have found export plugins for other formats, but no skp.
I'm still searching for a good solution to "link" skp files to 3ds max. There is this import link manager for max that could work quite well for me...
http://www.mirarkitektur.com/mirzasoftwares/?menu=presentationProduit&product=Mirza%20Link%20ManagerI could import the whole model, but this can take some time for bigger files, so i think splitting up the model in several parts would be helpful. If i modify the model only the changed parts need to be updated.
So my question is, if someone could set up an export routine where you can export (and overwrite on update) only selected parts to a folder.
The best thing would be if it would be possible to specify an export folder that is defined in the project (is it possible to store such attributes?) and export/update the selected groups or components with their definition names with click on a button or an entry in the right click menu.
(A more advanced option could be a link manager like "Cross Reference Organizer" (https://extensions.sketchup.com/en/content/cross-reference-organizer) where all parts would be listed and could be refreshed) -
Hide unwanted, save file and open it in Max. Max skips hidden geometry
-
link aux max files (containing skp geometry) in centralized (host) max file.
-
Thanks for the suggestion, but i need separate files to link them in max. If i link the same file several times with different hidden parts the imported geo will be overwritten.
And if i have to hide parts first and then save the file i can also select the modified groups one by one and export them via right click menu, as i do it now. I was searching for a more automated solution for bigger models, where i would split the model in more parts to make it faster to update in max. -
You have the option from Component browser/In model Components - Save to local colection which saves all components from the model to SU components library
-
It doesn't preserve location
-
The attached code should do something like you want...
Note the following:
You must have saved the model before running this.
You must have at least a group and/or a component-instance preselected before running this.
Individual groups are exported using their given-name, or if unnamed as 'Group#N' where N is the count.
Individual instances are exported using their definition-name, with a '#N' count suffix added if there's more than one instance of that definition.
These exported SKPs are put into the same folder as the model itself.
It reports the files it has exported as it goes.
The exported file's thumbnails should be accurate.
It removes any backup files made during the process, and on completion it reverts to the original model's contents.
All temporary deletions etc are 'aborted', so that although the exported files get made successfully, the original model should remain unchanged.
To use the code simply copy all of it and paste it into the Ruby Console and press <enter>.
Note the preselection requirement !
If it works as you hope, then I can make it into a RB file, with a menu item etc for you...mo=Sketchup.active_model pa=mo.path if pa.empty? UI.messagebox("Save 'Untitled' Model Before Exporting...") else d=File.dirname(pa).tr("\\", "/") es=mo.active_entities.to_a ss=mo.selection.to_a mo.selection.clear gs=ss.grep(Sketchup;;Group) gis=gs.collect{|e| e.persistent_id } is=ss.grep(Sketchup;;ComponentInstance) iis=is.collect{|e| e.persistent_id } unless gis[0] || iis[0] UI.messagebox("Select Groups and/or Instances Before Exporting...") else gis.each_with_index{|ii, i| e=nil mo.active_entities.to_a.each{|ee| if ee.persistent_id==ii e=ee break end } next unless e mo.start_operation("Export_group#{i}",true) n=e.name n="Group##{i+1}" if n.empty? p f=File.join(d, n+".skp") xs=es=mo.active_entities.to_a-[e] xs.each{|x| x.erase! if x.valid? } mo.save(f) if File.exist?(File.join(d, n+".skb")) #PC File.delete(File.join(d, n+".skb")) end if File.exist?(File.join(d, n+"~.skp")) #MAC File.delete(File.join(d, n+"~.skp")) end mo.abort_operation #revert model } iis.each_with_index{|ii, i| e=nil mo.active_entities.to_a.each{|ee| if ee.persistent_id==ii e=ee break end } next unless e mo.start_operation("Export_instance#{i}",true) n=e.definition.name n="#{n}##{i+1}" if e.definition.instances[1] p f=File.join(d, n+".skp") xs=es=mo.active_entities.to_a-[e] xs.each{|x| x.erase! if x.valid? } mo.save(f) if File.exist?(File.join(d, n+".skb")) #PC File.delete(File.join(d, n+".skb")) end if File.exist?(File.join(d, n+"~.skp")) #MAC File.delete(File.join(d, n+"~.skp")) end mo.abort_operation # revert model } mo.save(pa) # revert back to orignal model end end puts "Done."
-
Thank you very much TIG! But i'm getting an error message...
Error; #<NoMethodError; undefined method `persistent_id' for #<Sketchup;;ComponentInstance;0x0000002558bb80>> <main>;12;in `block in <main>' <main>;12;in `collect' <main>;12;in `<main>' SketchUp;1;in `eval'
I tried with components and groups.
-
@srx This saves ALL components of a model.
-
I just noticed that the SketchUp version you have is <2016.
Therefore "Persistent IDs" cannot be used - these are needed to circumvent the lost IDs during newer SketchUp processes...Try this alternative [which will fail with >=2016 ! but should still work in older versions ?? ]
mo=Sketchup.active_model pa=mo.path if pa.empty? UI.messagebox("Save 'Untitled' Model Before Exporting...") else d=File.dirname(pa).tr("\\", "/") es=mo.active_entities.to_a ss=mo.selection.to_a mo.selection.clear gs=ss.grep(Sketchup;;Group) gis=gs.collect{|e| e.guid } is=ss.grep(Sketchup;;ComponentInstance) iis=is.collect{|e| e.guid } unless gis[0] || iis[0] UI.messagebox("Select Groups and/or Instances Before Exporting...") else gis.each_with_index{|ii, i| e=nil mo.active_entities.to_a.each{|ee| if ee.guid==ii e=ee break end } next unless e mo.start_operation("Export_group#{i}",true) n=e.name n="Group##{i+1}" if n.empty? p f=File.join(d, n+".skp") xs=es=mo.active_entities.to_a-[e] xs.each{|x| x.erase! if x.valid? } mo.save(f) if File.exist?(File.join(d, n+".skb")) #PC File.delete(File.join(d, n+".skb")) end if File.exist?(File.join(d, n+"~.skp")) #MAC File.delete(File.join(d, n+"~.skp")) end mo.abort_operation #revert model } iis.each_with_index{|ii, i| e=nil mo.active_entities.to_a.each{|ee| if ee.guid==ii e=ee break end } next unless e mo.start_operation("Export_instance#{i}",true) n=e.definition.name n="#{n}##{i+1}" if e.definition.instances[1] p f=File.join(d, n+".skp") xs=es=mo.active_entities.to_a-[e] xs.each{|x| x.erase! if x.valid? } mo.save(f) if File.exist?(File.join(d, n+".skb")) #PC File.delete(File.join(d, n+".skb")) end if File.exist?(File.join(d, n+"~.skp")) #MAC File.delete(File.join(d, n+"~.skp")) end mo.abort_operation # revert model } mo.save(pa) # revert back to orignal model end end puts "Done."
-
@tig said:
I just noticed that the SketchUp version you have is <2016.
Therefore "Persistent IDs" cannot be used - these are needed to circumvent the lost IDs during newer SketchUp processes...Oh sorry, i wasn't aware of that.
Thanks for the update. It's working great now! Very cool.
Could you put it into the right click menu to the other export options?Btw. is it possible to configure the right click menu? The list is getting very long and there are some entries that i never use. I somehow remember that this wasn't possible and you had to change it in the plugin code. If this is the case, is there a single command that can be commented out to deactivate it without generating problems or is it more complex?
-
@TIG Error: #<SyntaxError: <main>:4: syntax error, unexpected
else' <main>:15: syntax error, unexpected
else'
else
^~~~
<main>:23: syntax error, unexpected '}', expecting end-of-input
}
^SketchUp:in `eval'
It keeps showing this error in su 2021
-
@MartinGr
I can't see where that error is arising.
Unfortunately any old 'ruby' formatted text is FUBAR on the new forum - Gábor is working on a fix:
Here's a rewritten version that works for me...mo=Sketchup.active_model pa=mo.path if pa.empty? UI.messagebox("Save 'Untitled' Model Before Exporting...") else d=File.dirname(pa).tr("\\", "/") es=mo.active_entities.to_a ss=mo.selection.to_a mo.selection.clear gs=ss.grep(Sketchup::Group) gis=gs.collect{|e| e.persistent_id } is=ss.grep(Sketchup::ComponentInstance) iis=is.collect{|e| e.persistent_id } unless(gis[0] || iis[0]) UI.messagebox("Select Groups and/or Instances Before Exporting...") else gis.each_with_index{|ii, i| e=nil mo.active_entities.to_a.each{|ee| if ee.persistent_id==ii e=ee break end } next unless e mo.start_operation("Export_group#{i}",true) n=e.name n="Group##{i+1}" if n.empty? p f=File.join(d, n+".skp") xs=es=mo.active_entities.to_a-[e] xs.each{|x| x.erase! if x.valid? } mo.save(f) if File.exist?(File.join(d, n+".skb")) #PC File.delete(File.join(d, n+".skb")) end if File.exist?(File.join(d, n+"~.skp")) #MAC File.delete(File.join(d, n+"~.skp")) end mo.abort_operation #revert model } iis.each_with_index{|ii, i| e=nil mo.active_entities.to_a.each{|ee| if ee.persistent_id==ii e=ee break end } next unless e mo.start_operation("Export_instance#{i}",true) n=e.definition.name n="#{n}##{i+1}" if e.definition.instances[1] p f=File.join(d, n+".skp") xs=es=mo.active_entities.to_a-[e] xs.each{|x| x.erase! if x.valid? } mo.save(f) if File.exist?(File.join(d, n+".skb")) #PC File.delete(File.join(d, n+".skb")) end if File.exist?(File.join(d, n+"~.skp")) #MAC File.delete(File.join(d, n+"~.skp")) end mo.abort_operation # revert model } mo.save(pa) # revert back to original model end end puts "Done."
-
This one will perhaps be useful to you:
[https://sketchucation.com/plugin/2667-componentsplus]
Regards,
Advertisement