[C API] Selected Entities in SU 2017-2020.1

A new, very needed SUSelectionGetEntityList() has been added in C API in SU2020.2. Thanks to SU Team.

For older SU versions I can convert a Ruby selection into a vector of SUEntityRef, but this is not enough.

Is there a way to create SUEntitiesRef instead? This way it could be passed to the same function as a result of SUModelGetEntities().

Not directly. This is an internal collection class object that is “owned” by either the model object or a SUComponentDefinitionRef object.

In other words these two objects cannot exist without having this collection of entities, but the collection can be empty (if the “owner” object has just been created or if all the entity members of the collection have been deleted.)

You can create a temporary definition to hold entity objects for a spell. We do this in the Ruby usually it’s a group definition.

What is “the same function” ?

The entity objects in a selection are not “owned” by the selection collection. They are still a member of an entities collection (either the model’s or some definition’s.) Think of the selection as just a list of pointers.

I was hoping that I can find this list of pointers to be used directly by my own function that expects SUEntitiesRef - same as a result of SUModelGetEntities().

I simply need now a separate function for exporting a selection, but I have found that I can live with it. It wasn’t that complicated in the end.


in older versions … there is no C exposure to the selection collection.

But, there always was exposure to the Ruby API. And Ruby itself is implemented in C.
So you can make SketchUp Ruby API calls from the C side.

You would need to find a way to convert the Ruby C types to SketchUp C API types.
(They made this easier in ver 2020.2 by adding conversion functions.)

See the downloadable Ruby Book list for PDF book:
Extending Ruby 1.9: Writing Extensions in C

1 Like