How to change the layer of a group (and ALL of its entities)
-
I've noticed I spent more time tidying up [all my entities into appropriate layers], than actually working on something. Once I'm done tidying up, I forget what actually wanted to do!
This is partially because of the fact that when I move a certain group to a different layer, the entities within the group stay on the initial layer, the one they were on before 'moving'. This slows me down immensely.
Of course, at times, this 'feature' is useful, but is there a way to change the layer for the WHOLE content of the group/component into a new/different layer?
Thank you for your time/reading!
Cheers
H.G.
-
A quick manual way is to double click the group so all of the innards are the active entities.
Edit>SelectAll[Ctrl+A]
Then use Entity Info or the Layer toolbar's drop-down list to change their layer to whatever you wish... You might need/want to mine down into nested groups to change their contents too...To do it 'in code' use one of these one-liners, copy/pasted into the Ruby Console +<enter>.
All Groups in the current selection have their contents put on the same layer as the group itself...m=Sketchup.active_model;m.start_operation('g');m.selection.grep(Sketchup;;Group).each{|g|g.make_unique if g.entities.parent.instances[1];g.entities.each{|e|e.layer=g.layer}};m.commit_operation
Of course it's wise usually to leave 'raw geometry' on Layer0, so this second version only processes non-geometry, and leaves raw geometry alone...
m=Sketchup.active_model;m.start_operation('g');m.selection.grep(Sketchup;;Group).each{|g|g.make_unique if g.entities.parent.instances[1];g.entities.each{|e|e.layer=g.layer unless e.is_a?(Sketchup;;Edge) || e.is_a?(Sketchup;;Face)}};m.commit_operation
This one moves all raw geometry onto Layer0 and matches other objects to the group's layer
m=Sketchup.active_model;m.start_operation('g');m.selection.grep(Sketchup;;Group).each{|g|g.make_unique if g.entities.parent.instances[1];g.entities.each{|e|if e.is_a?(Sketchup;;Edge) || e.is_a?(Sketchup;;Face);e.layer=nil;else;e.layer=g.layer;end}};m.commit_operation
They are all one step undo-able.
-
Thanks so much for this!
How would I define a key with that one-liner? Tried googling, but the post on RUBY ON WINDOWS gives me such a headache
-
You can't.
It needs a command/menu entry which you can then shortcut to...
This generic code does that:require("sketchup.rb") module HamletG def self.toolx() ### paste a one-liner here - without any initial ### end unless file_loaded?(__FILE__) UI.menu("Plugins").add_item("HamletG's toolx"){self.toolx()} end file_loaded(__FILE__) end
Adjust 'toolx' for your tool's name [lowercase letters starting with a-z] - copy this into code a plain text file in the Plugins folder named 'HamletG-toolx.rb', where you need to adjust 'toolx' etc to match the tool's method... Set a shortcut to the new "Plugins" menu item after a restart... The "HamletG's toolx" in the menu item's title can of course say whatever you like...
-
Cheers, but there seems to be an error with those one liners :
For instance the first one;
{ruby}:
m=Sketchup.active_model;m.start_operation('g');m.selection.grep(Sketchup::Group).each{|g|g.make_unique if g.instances[1];g.entities.each{|e|e.layer=g.layer}};m.commit_operation Error: #<NoMethodError: undefined method
instances' for #Sketchup::Group:0xf739b78>
(eval):155
(eval):155:ineach' (eval):155
-
@gonashvili said:
This is partially because of the fact that when I move a certain group to a different layer, the entities within the group stay on the initial layer, the one they were on before 'moving'. This slows me down immensely.
From this comment it seems you might benefit from reading through the help files on the use of layers in SketchUp. Especially these passages:
@unknownuser said:
First things first: by default, a SketchUp model has one layer, Layer 0 (zero), which is the base layer. You can't delete or rename Layer 0, and you should always draw your individual entities on Layer 0 and leave them there.
@unknownuser said:
Always draw your entities on Layer 0 and leave them there.
If you follow the "rules" about using layers in SketchUp and use them correctly you will find it doesn't slow you down at all.
-
@gonashvili said:
Cheers, but there seems to be an error with those one liners...
You are right - my typo ! Now it's corrected in my original post... -
Thank you so much. I'd buy you a coffee or something if I had any money right now
Advertisement