by CadFather » Sat Jun 16, 2012 2:33 pm
This is a plugin by TIG to align all model components to a grid. The menu has a choice of 7 different spacings. you'll find it in the 'Tools' menu components_grid.rb
Last edited by CadFather on Sat Jun 23, 2012 10:34 am, edited 3 times in total.
-

CadFather
- PluginStore Author

-
- Posts: 1032
- Joined: Fri Nov 16, 2007 11:03 am
- Location: London, Milano, Sicily
- Name: CadFather
- Operating system: Windows
- SketchUp version: 2014
- License type: Pro
- SketchUp use: landscape architecture
- Level of SketchUp: Advanced
-
by Dave R » Sat Jun 16, 2012 3:13 pm
Just save the In Model component library as a local collection in its own folder. Now you have all the components as individual files in a folder on your hard drive. Copy it to whatever other disk you want. No plugin needed.
Etaoin Shrdlu
%
(THERE'S NO PLACE LIKE)
G28 X0.0 Y0.0 Z0.0
M30
%
-

Dave R
- Global Moderator
-
- Posts: 18113
- Joined: Tue Nov 13, 2007 11:52 pm
- Location: SE Minnesota
- Name: Dave R
- Operating system: Windows
- SketchUp version: 2021
- License type: Pro
- SketchUp use: woodworking
- Level of SketchUp: Advanced
by CadFather » Sat Jun 16, 2012 3:18 pm
..of course!  ..thanks Dave - that's brilliant, and it brings me back to the early days when that was exactly how we did things... 
-

CadFather
- PluginStore Author

-
- Posts: 1032
- Joined: Fri Nov 16, 2007 11:03 am
- Location: London, Milano, Sicily
- Name: CadFather
- Operating system: Windows
- SketchUp version: 2014
- License type: Pro
- SketchUp use: landscape architecture
- Level of SketchUp: Advanced
-
by Dave R » Sat Jun 16, 2012 3:22 pm
Etaoin Shrdlu
%
(THERE'S NO PLACE LIKE)
G28 X0.0 Y0.0 Z0.0
M30
%
-

Dave R
- Global Moderator
-
- Posts: 18113
- Joined: Tue Nov 13, 2007 11:52 pm
- Location: SE Minnesota
- Name: Dave R
- Operating system: Windows
- SketchUp version: 2021
- License type: Pro
- SketchUp use: woodworking
- Level of SketchUp: Advanced
by TIG » Sat Jun 16, 2012 3:25 pm
There is a built-in way BUT if you want it coded then use an iteration of https://developers.google.com/sketchup/ ... on#save_asThis one-liner, copy/pasted into the Ruby Console + <enter> will export all definitions in the model into the model's folder - named after the definition+.skp - Code: Select all
m=Sketchup.active_model;p=File.dirname(m.path).tr("\\","/");puts"\n\nExporting Components to\n\n"+p+"\n\n";ds=m.definitions;ns=[];ds.to_a.find_all{|d|next if d.group?||d.image?;ns<<d.name};ns.sort.each{|n|puts s=n+".skp";ds[n].save_as(File.join(p,s))};puts"\nDone."
If you want groups or images exported adjust the 'trap' next if...
TIG
-

TIG
- Global Moderator
-
- Posts: 20260
- Joined: Mon Nov 12, 2007 7:24 pm
- Location: Northumbria UK
- Name: TIG
- Operating system: Windows
- SketchUp version: 2021
- License type: Pro
- SketchUp use: architecture
- Level of SketchUp: Advanced
by CadFather » Sat Jun 16, 2012 3:36 pm
TIG, you do it on purpose! 
-

CadFather
- PluginStore Author

-
- Posts: 1032
- Joined: Fri Nov 16, 2007 11:03 am
- Location: London, Milano, Sicily
- Name: CadFather
- Operating system: Windows
- SketchUp version: 2014
- License type: Pro
- SketchUp use: landscape architecture
- Level of SketchUp: Advanced
-
by CadFather » Sat Jun 16, 2012 4:16 pm
while i'm at it i might ask another question (for which there surely there isn't an old easy answer..)
any way to distribute ALL the components present in the component browser 'in model' - to an imaginary grid in model space?
-

CadFather
- PluginStore Author

-
- Posts: 1032
- Joined: Fri Nov 16, 2007 11:03 am
- Location: London, Milano, Sicily
- Name: CadFather
- Operating system: Windows
- SketchUp version: 2014
- License type: Pro
- SketchUp use: landscape architecture
- Level of SketchUp: Advanced
-
by TIG » Sat Jun 16, 2012 5:16 pm
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: - Code: Select all
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...
TIG
-

TIG
- Global Moderator
-
- Posts: 20260
- Joined: Mon Nov 12, 2007 7:24 pm
- Location: Northumbria UK
- Name: TIG
- Operating system: Windows
- SketchUp version: 2021
- License type: Pro
- SketchUp use: architecture
- Level of SketchUp: Advanced
by CadFather » Sat Jun 16, 2012 5:51 pm
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) compogrid.rb
-

CadFather
- PluginStore Author

-
- Posts: 1032
- Joined: Fri Nov 16, 2007 11:03 am
- Location: London, Milano, Sicily
- Name: CadFather
- Operating system: Windows
- SketchUp version: 2014
- License type: Pro
- SketchUp use: landscape architecture
- Level of SketchUp: Advanced
-
by TIG » Sat Jun 16, 2012 11:07 pm
You miss called the module/method... try it this way - Code: Select all
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 !
TIG
-

TIG
- Global Moderator
-
- Posts: 20260
- Joined: Mon Nov 12, 2007 7:24 pm
- Location: Northumbria UK
- Name: TIG
- Operating system: Windows
- SketchUp version: 2021
- License type: Pro
- SketchUp use: architecture
- Level of SketchUp: Advanced
by CadFather » Sun Jun 17, 2012 10:51 am
thanks TIG - works great. i think there's a small typo here: 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 dswhat's interesting is how fast it is even with lots of components 
-

CadFather
- PluginStore Author

-
- Posts: 1032
- Joined: Fri Nov 16, 2007 11:03 am
- Location: London, Milano, Sicily
- Name: CadFather
- Operating system: Windows
- SketchUp version: 2014
- License type: Pro
- SketchUp use: landscape architecture
- Level of SketchUp: Advanced
-
by TIG » Sun Jun 17, 2012 12:13 pm
You are right - I have now changed the original to 'ds'...
TIG
-

TIG
- Global Moderator
-
- Posts: 20260
- Joined: Mon Nov 12, 2007 7:24 pm
- Location: Northumbria UK
- Name: TIG
- Operating system: Windows
- SketchUp version: 2021
- License type: Pro
- SketchUp use: architecture
- Level of SketchUp: Advanced
by CadFather » Sat Jun 23, 2012 10:30 am
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.. 
-

CadFather
- PluginStore Author

-
- Posts: 1032
- Joined: Fri Nov 16, 2007 11:03 am
- Location: London, Milano, Sicily
- Name: CadFather
- Operating system: Windows
- SketchUp version: 2014
- License type: Pro
- SketchUp use: landscape architecture
- Level of SketchUp: Advanced
-
by TIG » Sat Jun 23, 2012 10:41 am
This [simpler] version spaces the component-instances 2m apart along the red/x axis [no stacking into a 'square'] - Code: Select all
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 the x=2.m for a different spacing in red/x if desired...
TIG
-

TIG
- Global Moderator
-
- Posts: 20260
- Joined: Mon Nov 12, 2007 7:24 pm
- Location: Northumbria UK
- Name: TIG
- Operating system: Windows
- SketchUp version: 2021
- License type: Pro
- SketchUp use: architecture
- Level of SketchUp: Advanced
by gullfo » Sat Jun 23, 2012 4:47 pm
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...
-

gullfo
-
- Posts: 122
- Joined: Mon Dec 10, 2007 5:19 am
- Location: Old Tappan, NJ USA
- Name: Glenn Stanton
- Operating system: Windows
- SketchUp version: 2021
- License type: Pro
- SketchUp use: architecture
- Level of SketchUp: Advanced
-
by TIG » Sat Jun 23, 2012 9:01 pm
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] - Code: Select all
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
-

TIG
- Global Moderator
-
- Posts: 20260
- Joined: Mon Nov 12, 2007 7:24 pm
- Location: Northumbria UK
- Name: TIG
- Operating system: Windows
- SketchUp version: 2021
- License type: Pro
- SketchUp use: architecture
- Level of SketchUp: Advanced
by Amazing Artist » Tue Jul 02, 2013 10:42 pm
TIG Thanks
That's my story, and I'm sticking to it!
-
Amazing Artist
-
- Posts: 28
- Joined: Sat Sep 15, 2012 3:59 am
- Name: Amazing Artist
by pilou » Wed Jul 08, 2020 12:14 am
For SU 2017 Make Incompatible with LightUP! Curiously icons of LightUp apear! bizarrerie.jpg 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! ) biz4.jpg
-

pilou
- Top SketchUcator
-
- Posts: 21098
- Joined: Wed Jan 23, 2008 10:33 pm
- Name: Pilou
- Operating system: Windows
- SketchUp version: 2017
- License type: Free/Make
- SketchUp use: hobby
- Level of SketchUp: Advanced
-
by juju » Thu Jul 09, 2020 12:29 pm
pilou wrote:For SU 2017 Make Incompatible with LightUP! Curiously icons of LightUp apear! bizarrerie.jpg 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! ) biz4.jpg
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?
Save the Earth, it's the only planet with chocolate.
-

juju
- Premium Member

-
- Posts: 2738
- Joined: Mon Oct 22, 2007 1:45 pm
- Location: Durbanville, Cape Town, South Africa.
- Name: Juju
- Operating system: Windows
- SketchUp version: 2021
- License type: Pro
- SketchUp use: architecture
- Level of SketchUp: Intermediate
by pilou » Thu Jul 09, 2020 1:50 pm
? 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! 
-

pilou
- Top SketchUcator
-
- Posts: 21098
- Joined: Wed Jan 23, 2008 10:33 pm
- Name: Pilou
- Operating system: Windows
- SketchUp version: 2017
- License type: Free/Make
- SketchUp use: hobby
- Level of SketchUp: Advanced
-
by pilou » Thu Jul 09, 2020 2:23 pm
Alas not better ! My SketchUp is absolutly new! Only "Component on Grid" installed! So no conflict possible! (like Light Up above) not_better.jpg If i add new volumes : the same! that is making snowball ! All is redrawn! 
-

pilou
- Top SketchUcator
-
- Posts: 21098
- Joined: Wed Jan 23, 2008 10:33 pm
- Name: Pilou
- Operating system: Windows
- SketchUp version: 2017
- License type: Free/Make
- SketchUp use: hobby
- Level of SketchUp: Advanced
-
by Ad Machine » 5 minutes ago
-
Ad Machine
- Robot
-
- Posts: 2012
-
Return to Plugins
|