Select all comps if contain name
- 
 if this code gets all comps named 'arete' Sketchup.active_model.selection.add( Sketchup.active_model.definitions['Arete'].instances )how can i select ALL the comps that may contain it as well? (like Arete_1, Arete_2 etc) 
- 
 m=Sketchup.active_model;e=m.active_entities;s=m.selection;s.clear;a=[]; m.definitions.to_a.select{|d|d.name=~/[Aa]rete/}.each{|d|d.instances.each{|i|a<<i if i.parent.entities==e}};s.add(a)if a[0]It clears the selection first, then because it could select instances across context boundaries, thereby causing splatting issues, I use the array ' a' to select only those instances in themodel.active_entities!
 The pattern-matching=~/[Aa]rete/matches upper and lower case A, to limit it to just what's at the start use=~/^[Aa]rete/, to the end=~/[Aa]rete$/, to allow for ê or one other letter, use=~/[Aa]r.te/, or perhaps=~/[Aa]r[eê]te/
- 
 Wow, super comprehensive, TIG - thank you. are you also saying that i should not be selecting comps inside other groups etc? suppose you wanted to swap an instance with another, across the whole model. are you risking bugsplats? 
- 
 Don't select anything unless you want to do something like Move/Copy... 
 You could make a transient selection to swap definitions etc, but it is a spalt-danger...
 BUT if you want to simply get a 'collection' of all instances - e.g. to swap them - use this:m=Sketchup.active_model;a=[];m.definitions.to_a.select{|d|d.name=~/[Aa]rete/}.each{|d|a<<d.instances};a.flatten!;a.compact!;aThe variable ' a' is an array containing all of the matching instances, irrespective of their context.
 Note how you need to flatten to merge the instances arrays, and on the safe-side compact to remove any nil values...
- 
 brilliant, does more than i asked! need to study it a bit now (tax return can wait...) Thanks  
Advertisement


 
                             
                             
                             
                             
                             
                             
                            