Selecting all edges in selection cycling through groups
-
Is it possible, via ruby, to select all edges within a selection cycling through hierarchy (groups, components, nested groups etc...)?
My final goal is to paint them with the material of my choice.
Thanks in advance Ruby masters! -
Well, yeah it's possible. The current selection is an enumerator of Entities. Use its #grep method to extract the Entities of interest: Sketchup::Edge, Sketchup::Group, Sketchup::ComponentInstance. For loose Edges, you can immediately apply the material. For Groups or ComponentInstances, proceed recursively using that same process applied to the Group or ComponentInstance's ComponentDefinition's Entities collection instead of the active selection. The one thing you should be aware of is that for ComponentInstances, you can't color the Edges in one without also affecting them in all other instances regardless of where or how the others are nested. Similarly, if you have copied a Group, altering anything in one will make it unique from the others and will not affect them.
-
Hellobaldaman,
Here is an example code that will allow you to select all the edges:
def select_all_edges(ents, edges) ents.grep(Sketchup;;ComponentInstance).each do |e| e.definition.entities.grep(Sketchup;;Edge).each do |e| edges << e end select_all_edges(e.definition.entities, edges) end end edges = [] mod = Sketchup.active_model sel = mod.selection select_all_edges(sel, edges) sel.clear sel.add(edges)
Note that you do not have to select the edges to apply a ruby transformation on the edges.
Cordially
David
Advertisement