Getting an Array of Entities?



I’m surprised there no function to get an Array or Vector of entities. Something like SUEntitiesGetEntitiesArray(entities) maybe. Have I over-looked it?

I admit I do not have a specific goal in mind and am just playing around, but it would seem a useful function in some ways.


I put together an example for getting a list of entities out of curiosity and a desire to learn. It is posted on GitHub[1].

The code is fairly straightforward - I used a few standard containers like vector but the code is otherwise all functions - I did not use many c++ features like classes. I may add c++ classes at some point but I wanted to understand the SDK at the lower level also. Besides I’ve heard there may be a couple c++ wrappers already in the works.

The executable is a command line app that takes a .skp file name as the only input and just lists the model’s entities. This would be similar to the Ruby puts Sketchup.active_model.entities.to_a

One question I have is how to handle errors when calling the SU* functions? I know c++ had exceptions but it’s not clear how best to handle all the function calls that could go wrong throughout the file in a unified way. I am not even checking return values at this point.



This page lists enumerations ?

Does your implementation work so far ?

Ie, I notice you did not upcast the results of the getter functions to SUEntityRef before pushing them all into the same array. Is that dangerous in any way ?


Yes, it creates a model from a file, fills the vector with SUEntityRefs, and prints them out. Some entity types have not been added yet.

There is an upcast to SUEntityRef for each type that gets added to the vector.


Doh! Need new glasses. Sheesh, right there in plain text. :rolling_eyes:


There is one DrawingElement missing in the SDK - Text. All the other DrawingElements are available.