(Erase_entities within a group) rather boundingbox_pick in group

With ruby, I managed to select some entities I want to delete.They are in a group, sel = the selection.
So I tried using
group.entities.erase_entities sel
no luck.
If I do it at model level (not in a group) with
Sketchup.active_model.entities.erase_entities sel
works just fine.

Without seeing more of your code we can’t tell what you’ve done wrong !
I wouldn’t use the model.selection for this - at least not directly.
If you are working on something the user has selected use model.selection.to_a and pass that to the entities.erase_entities() method.
Otherwise just collect the objects into an array and pass that array to the method…

Selection is made with ruby, boundingbox, while in group.
I will try and make more explicit code.
now trying with model.active_entities

I see, it is boundingbox_pick not selecting when in the group.

ph = Sketchup.active_model.active_view.pick_helper
num_picked = ph.boundingbox_pick(boundingbox, Sketchup::PickHelper::PICK_INSIDE, tr)
if num_picked > 0

num_picked is 0, :frowning:

Why is the bounding box so importanat ?
Why not have the user preselect the objects to be deleted and then run the tool ?
But of course they could press ‘delete’ and skip using your tool altogether !

In your code how are you setting up the ‘boundingbox’ and the transformation ‘tr’?

The user selects a component (in a group) and then click to have it replaced. Then some edges and faces framing the component have to be erased. I use a copy of the bbox of the component as a boundingbox to select those. And the transformation of the components as well. Works fine in model but not in group. It does not pick.
So the real question, I realize now, is "Can a boundingbox_pick be used in a group? and how ? active_path?

Model#active_path= [my_group]

Well, my question was more like “Is active_path a way to get a boundingbox_pick in a group?”

Furthermore, isn’t there a contradictiion in this API docs excerpt.:

The [#active_path=] method is used to open a given instance path for editing.
It is expected that no entities are modified in an operation that opens/closes instances.

open for edit but do not modify !

Yes, I would agree the description is contradictory. Please open a API documentation issue on this.

Well I was suggesting that if it did not work from outside the group perhaps enter the group.
Your workflow states that the user will select an object inside the group. If you are going to let the native Selection tool do the selecting, then either your code or the user would have to enter the group in order to pick the nested component.

The main question: Does #bounding_box_pick() only work within the active entities context ?

When within a nested edit context the coordinates change on you into world coordinates instead of local coordinate values.

See: Sketchup::Model#edit_transform

I would think that the transformation passed to the Sketchup::PickHelper#bounding_box_pick would need to a combination, ie: group.transformation * instance.transformation

Also, I guess this method takes the place of Sketchup::PickHelper#do_pick ?

Actually, it is the inverse: What I said in other words is "bbox works fine when in model, but not when in a group; no select.

… I refer the distinguished gentleman to the comments I made some posts ago. :slight_smile:

Interesting indeed. Working on it.