Opening a group with the Ruby API in 2020, Is it possible?

Is this possible to do?

I know based on searching that it’s not possible previously, but am wondering if this is a capability in the SketchUp API now.

What I’m trying to do:
I’m attempting to have a user jump into a group of a selected face.

So I’m interested in:

  • The user selecting a face
  • Working out what group / component instance it’s in.
  • Then opening this instance for editing.

Correct …

… it was added in 2020.0.

If you want to deal with it post selection, then you can test the Selection set …

ss = Sketchup.active_model.selection
if !ss.empty? && ss.single_object? && ss.first.is_a?(Sketchup::Face)
  # do stuff
end

But there is a problem. If the user picked a face within a group (or instance) they’d need to be in that context, because if they back out, the selection set is cleared.

So, that rules out post selection, … so you need to write a Ruby tool class, and have your tool use the PickHelper class which can pick through contexts.

This is big problem because groups and instances do not actually “own” drawingelement entities.
It is their definition that has the entities collection.

Luckily, the PickHelper class has a #path_at method that lets you retrieve a path array of the nesting down to the face.

Make sure you read ThomThom’s help blog on PickHelper.