Casting a ComponentInstance to a Group in C API to simulate explode

To solve a problem in one of my applications I need to explode a (nested) component instance in the C API.

As there is no explode method in the C API (I checked the binaries again today, and the commented out SUGroupExplode method is not exported from the DLL), I’m trying to partially simulate explode functionality.

One of the things I’m trying is to downcast the SUComponentInstanceRef to an SUGroupRef using SUGroupFromComponentInstance

To test this, I do the following:

  1. Load the component using SUModelLoadDefinitionWithStatus.
  2. Create an instance using SUComponentDefinitionCreateInstance.
  3. Add this instance to the model entities as test, this works as expected, so the instance is correctly loaded.
  4. Downcast the instance to a group using SUGroupFromComponentInstance, which results in an empty SUGroupRef (null pointer). According to the documentation this indicates that the instance cannot be downcast to a group.

Does any one know why this could be? Or more specifically does anyone know what the prerequisites are for downcasting a SUComponentInstanceRef to an SUGroupRef in the C API. I cannot seem to find any documentaion on this.

I’ve tested this with both a nested and a non-nested component. The nested one looks like this:


What I’m trying to do here, is add the downcasted group to my model entities, like a poor mans explode. I might try to iterate recursively over ell entities in the component and see if I can add each entity to my model entities. That is more (tedious) work though.

If the C API is so limited, yo may consider doing the model generation in Ruby, via an instance of Sketchup:

  • on Windows, you can create a dedicated instance of Sketchup (in case the user has already one open)
  • on Mac, you just create a new model within the instance already created

Then a simple timer with a flag detection (say, existence of an instruction file) would launch your process.

Thanks for the suggestion. I am considering this approach, but prefer a solution where I don’t need to launch SketchUp for model generation or manipulation.

My programs mostly work quite well with the C API. Things sometimes get difficult for edge cases.

Over the years I have developed a set of libraries to work with SketchUp from within .NET Windows desktop applications. The investment in these libraries is huge and my users are very much used to the current workflow. If I really need to I will make the switch, probably only for certain functionality.

Switching to a scenario where I need to launch SketchUp will also incur a performance hit my users will not be happy with.

Going on 7 and a half years …

… but in this issue I noted that I did find reference to a SUGroupExplode() function in the C API header files. (It is at the bottom of "group.h".)

It was marked to not document, and my question WHY has never been answered.


@bugra

Unfortunately the latest release of the C API (2026.0.429) still doesn’t provide a way to explode groups. The above mentioned function is still commented out in group.h, and the method is also still not exported from the DLL.