Selecting Faces inside multiple groups



My extension creates several different groups and I was wondering if there was some Ruby Api that would allow me to select all faces inside the groups that lie on the x-y plane in order to apply a specific texture to them. The issue that I am running into is that since I’m dealing with multiple groups I cannot highlight faces from outside of the groups. Is this possible to do after all of the groups have been created, or do I have to apply the textures inside of each group separately?

Any help would be appreciated,

Thank you.


You can actually select multiple objects in the model by using the instance method ´add´ on the Selection object of the model. However this was never intended by the SketchUp developers, and it can cause odd behavior on movement, grouping or the like.

However you can work on objects in the model directly from Ruby without having them selected in the model. To find faces on the X Y plane you can check for faces with a normal that is parallel to the Z_AXIS using same_direction? If they have to be on the Z = 0plane you can check the Z of an arbitrary vertex.


‘Select’ is perhaps inappropriate - although you can actually make a selection-set that transcends various ‘contexts’, it probably not a good idea…

However, change the word to something like ‘Collect’ then that’s more useful…
So for example, let’s assume you collect all of your groups into an array called ‘groups’…
To collect all of the matching faces you use something like…

faces = []
    faces << face if face.normal.parallel?(Z_AXIS) && face.bounds.min.z==0
  face.material = "Red" # or whatever

This makes all flat faces at Z==0 ‘Red’…


This is what I was looking to do. Like you said, collect is a much better word than select for what I am trying to do. This should allow me to apply a certain texture my upward facing faces. Thanks.