Converting C struct to Ruby object

In the read only Live C API, let’s say we retrieve a reference to a group:

SUGroupRef group = ...

Now - is there a way to convert this C struct into a Ruby group object so that a face can be added?

It seems like it’s possible to retrieve the group with Model.find_entity_by_id.

With v2020.2 or higher, I believe you would upcast to a SUEntityRef using SUGroupToEntity()

… then use SUEntityToRuby() [see the ruby_api.h page]


Re the persistent id pattern, in older SketchUp versions I suppose yes you can get the group id with SUEntityGetPersistentID() after upcasting to SUEntityRef, and then pass the integer (or double) to the Ruby side using the Ruby C API macros. INT2NUM ?

Excellent.

1 Like