[Plugin] Components to Grid
-
I already recently did something like this in another thread, where the OP wanted to import SKPs and then show the components laid out.
What you could do with a model's components in code is to iterate the list of definition names 'ns' [as all set/got in my earlier example] and then place an instance of each on a special layer [it makes later deletions easier], thus:m=Sketchup.active_model;m.start_operation("ALL!");ds=m.definitions;ns=[];ds.to_a.find_all{|d|next if d.group?||d.image?;ns<<d.name};ns.sort!; l=m.layers.add("ALL!");puts"\nLaying out ALL Components...\n\n"; es=m.active_entities; p=Geom;;Point3d.new(0,0,0);x=1.m;y=1.m;r=(Math.sqrt(ns.length)+0.5).to_i;c=0; ns.length.times{|i|puts ns[i]; tr=Geom;;Transformation.new(p); n=es.add_instance(ds[ns[i]],tr);n.layer=l;c+=1;if c>=r;p.x=0;p.y+=y;c=0;else;p.x+=x;end};puts"\nDone.";m.commit_operation
The x/y set for a 1m 'square' grid starting from [0,0,0] - with any odd ones on the final row - so adjust this as desired; these new instances are put onto a layer name 'ALL!'; this one-liner is one-step undoable...
-
wow...thank you TIG - just tried it and it's fab!
tried to make it into a command but no success and yet i'm sure i wrapped it up properly (just in case others find it useful)
-
You miss called the module/method... try it this way
require 'sketchup.rb' module CADfather unless file_loaded?(File.basename(__FILE__)) UI.menu('Tools').add_item('Components to Grid'){self.compogrid()} end file_loaded(File.basename(__FILE__)) def self.compogrid() m=Sketchup.active_model;m.start_operation("ALL!");ds=m.definitions;ns=[]; ds.to_a.find_all{|d|next if d.group?||d.image?;ns<<d.name};ns.sort!; l=m.layers.add("ALL!");puts"\nLaying out ALL Components...\n\n"; es=m.active_entities; p=Geom;;Point3d.new(0,0,0);x=2.m;y=2.m;r=(Math.sqrt(ns.length)+0.5).to_i;c=0; ns.length.times{|i|puts ns[i]; tr=Geom;;Transformation.new(p); n=es.add_instance(ds[ns[i]],tr);n.layer=l;c+=1;if c>=r;p.x=0;p.y+=y;c=0;else;p.x+=x;end};puts"\nDone.";m.commit_operation end #def end #module
... OR something similar ...
EDIT: typo fixed ! -
thanks TIG - works great.
i think there's a small typo here:
%(#008000)[def self.compogrid()
m=Sketchup.active_model;m.start_operation("ALL!");ds=m.definitions;ns=[];]s.to_a.find_all{|d|next if d.group?||should read ds
what's interesting is how fast it is even with lots of components
-
You are right - I have now changed the original to '
ds
'... -
Hi TIG - is it possible to have all the components placed along the red axis? i tried modifying the script but i always get the components on top of each other..
-
This [simpler] version spaces the component-instances 2m apart along the red/x axis [no stacking into a 'square']
require 'sketchup.rb' module CADfather unless file_loaded?(File.basename(__FILE__)) UI.menu('Tools').add_item('Components to Grid'){self.compogrid()} end file_loaded(File.basename(__FILE__)) def self.compogrid() m=Sketchup.active_model;m.start_operation("ALL!"); ds=m.definitions; ns=[]; ds.to_a.find_all{|d|next if d.group?||d.image?; ns<<d.name}; ns.sort!; l=m.layers.add("ALL!");puts"\nLaying out ALL Components...\n\n"; es=m.active_entities; p=Geom;;Point3d.new(0,0,0); x=2.m; ns.length.times{|i|puts ns[i]; tr=Geom;;Transformation.new(p); n=es.add_instance(ds[ns[i]],tr);n.layer=l; p.x+=x};puts"\nDone.";m.commit_operation end #def end #module
If the Ruby Console is open it reports what it's doing...
Change thex=2.m
for a different spacing in red/x if desired... -
Thanks TIG - much appreciated - i'll try integrating it into the grid plugin..
-
TIG script examples - an interesting side effect - if you have a component made of other components it pulls it apart and distributes them... in this example i have a DC component of an acoustic window which has frames and seals as sub-components. in a way, this could be handy for creating a "how to assemble" guide because it pulls it apart in order of nesting...
otoh this may not be a desired effect for the script in the end...
-
The OP asked for all components to be displayed on a grid.
The code is very adaptable.
It ignores Groups and Images although it could as easily display those as well, or instead.
This version displays just components that have instances that are either in the model's entities or inside a non-component-entities context [i.e. inside a group that is not itself inside a component definition]require 'sketchup.rb' module CADfather unless file_loaded?(File.basename(__FILE__)) UI.menu('Tools').add_item('Components to Grid'){self.compogrid_used()} end file_loaded(File.basename(__FILE__)) def self.compogrid_used() m=Sketchup.active_model m.start_operation("ALL!") ds=m.definitions ns=[] def self.recurse_parent(c) begin return c.parent rescue return nil end end ds.to_a.find_all{|d| next unless d.instances[0] next if d.group? next if d.image? skip=true d.instances.each{|i| if i.parent==m skip=false break elsif i.parent.group? i.parent.instances.each{|g| c=g while c c=self.recurse_parent(c) if m==c skip=false c=nil break end end } end } next if skip ns<<d.name } ns.sort!; l=m.layers.add("ALL!") puts"\nLaying out ALL Components...\n\n" es=m.active_entities p=Geom;;Point3d.new(0,0,0); x=2.m ns.length.times{|i| puts ns[i] tr=Geom;;Transformation.new(p) n=es.add_instance(ds[ns[i]],tr) n.layer=l p.x+=x} puts"\nDone." m.commit_operation end #def end #module
-
TIG Thanks
-
For SU 2017 Make
Incompatible with LightUP!
Curiously icons of LightUp apear!And LightUp Disconnected
don't take a selection but all components on the scene!Here must be display only "XTE" Selected : that is not the case!
All is recalled! (even the top view text who is not visible at the Plugin call! ) -
@pilou said:
For SU 2017 Make
Incompatible with LightUP!
Curiously icons of LightUp apear![attachment=1:2yvqwupx]<!-- ia1 -->bizarrerie.jpg<!-- ia1 -->[/attachment:2yvqwupx]
And LightUp Disconnected
don't take a selection but all components on the scene!Here must be display only "XTE" Selected : that is not the case!
All is recalled! (even the top view text who is not visible at the Plugin call! )[attachment=0:2yvqwupx]<!-- ia0 -->biz4.jpg<!-- ia0 -->[/attachment:2yvqwupx]
Pilou, are you OK? I don't see what this has to do with the thread above? Perhaps start your own thread or look for the thread this is supposed to be in?
-
?
It's not the thread about Plugin "Components to Grid"?
What better place to report that it is not compatible (for me in any case) with Light UP ?
And it has curious behavior with the selection Components ? (for me in any case)Out of that i just reinstall SketchUp and must verify if above is always true!
It will be my first Plugin to reload from a little thousand! -
Alas not better !
My SketchUp is absolutly new! Only "Component on Grid" installed!So no conflict possible! (like Light Up above)
If i add new volumes : the same! that is making snowball ! All is redrawn!
Advertisement