Make group from array of faces


I am trying to make a group from an array of sorted faces, but can’t quite figure out how this best can be done. I see that many recommend to make an empty group first and then to add the entities, but still I cannot seem to get it to work.

So my question is, how do I create an empty group first and then add the faces to the group.

The array of faces looks like this:

  > [#<Sketchup::Face:0x000000260ffac0>, #<Sketchup::Face:0x000000260ff188>, #<Sketchup::Face:0x000000260fef08>, #<Sketchup::Face:0x000000260fed28>, #<Sketchup::Face:0x000000260fea80>, #<Sketchup::Face:0x000000260ff908>]
And this is the error message I get:

      > Error: #<NoMethodError: undefined method `add_group' for #<Array:0x00000026143cc0>>

You don’t give us much to go on…
Assuming that all of the array of ‘faces’ are within the ‘model.active_entities’ context, AND that you will make the group in that same context too…

face_group = model.active_entities.add_group(faces)

The listed faces and their edges not needed to support excluded faces will be moved into the group.

You can always ‘move’ it into another context later with:

moved_group = some_other_entities.add_instance(face_group.entities.parent, face_group.transformation)

You cannot make a group of existing faces that are in a context other than the model.active_entities, even if you keep the same context for the group, this cross-threading will usually make a BugSplat!

If you want to do this you need to copy the faces into the new group [initially created empty] with:

copy_group = some_entities_context.add_group()

Then iterate the faces and replicate the them one at a time inside the copy_group.entities using:

new_face = copy_group.entities.add_face(face_outer_loop.vertices)

BUT if you know the face will have some holes [if face.loops[1] ...], then you need to collect the vertices of the inner holes, make those temporary faces and then make the other loop face, erasing the inner unwanted ones afterwards…

outer_loop = face.outer_loop
inner_loops = face.loops - [outer_loop]
holes = []
  holes << copy_group.entities.add_face(loop.vertices)
copy_group.entities.erase_entities(holes) if holes[0]

This is repeated for each face.
If you want to ‘move’ rather than ‘copy’ the faces, you need to iterate them and collect their edges [making sure to NOT include any edges which support a face not inside ‘faces’], then erase the faces and those edges…


My apologies, I see that my post was not very informative. I guess it can be a bit challenging to describe a problem when you don’t understand the concepts very well.

From what I understand, my problem is that I want to make a group of faces, but in reality a group needs other entities such as edges to make the group. It seems like it was the context I didn’t quite understand, but I followed your advise and it worked perfectly!

Thanks a lot :slight_smile: