Get Instance transformation in reference to model root



Dear all,

I’m creating a custom SKP exporter to a proprietary file structure.

I’m using the C++ SDK.

Everything is going great but I’m at a loss for one thing,
The transformations to get the points on the correct place in the complete model.

As documented SUComponentInstanceGetTransform retrieves the transformation according to the parent.
But there is no way to know what the parent is of the instance?
Or even better, there is no easy way to change the parent or get the transformation in reference to the model root.

Or am I missing a function/documentation?

With kind regards,
Rudi de Kruijf


I don’t have any experience with the SDK, but based on my experience with the SketchUp DOM from using the Ruby API, the parent of a component instance is a component definition, not the containing component instance.

This means one single component instance can be placed on multiple different places in the model, if any of its parent components has more than one instance. To specify the location of a component instance in model space you must specify the path of instances leading down the hierarchy to it. Only in the trivial case of exactly one instance of each parent definition, you can know the position in model space only from an instance.’

Typically when exporting geometry (to formats that don’t have SketchUp’s definition/instance model) you traverse the document hierarchy from root to leaf, thus always having a reference to the parent instances, and their transformations.

This example shows how you can traverse or “drill into” a model recursively, while maintaining a reference to the local transformation. It’s written in Ruby but maybe can be helpful anyway to understand the “model model”.


Here’s a picture to illustrate what @eneroth is talking about. In this very simple model there are three Components, cleverly named Component#1, Component#2, and Component#3. The model contains one instance of Component#1 and two instances of Component#3, which nests one instance each of Component#1 and Component#2. I used leader text to label instances of Component#1 and Component#2 but had to select the instances of Component#3 so that their bounding boxes are visible.

Looking at the figure you might think that there are three instances of Component#1 and two of Component#2, but if you probe the model’s contents you find that Component#1 only admits having two instances and Component#2 has only one instance. That’s because one instance of Component#1 has the model as its parent, and the other has Component#3’s definition as its parent. All instances of Component#2 have Component#3’s definition as their parent.

So you have to start at the root level and work your way forward through the instance nesting to track everything down.


Thank you @eneroth3 @slbaumgartner

That part I understand.

The problem I have getting this into code.

I can get all instances of all components, and get the transformations of the instances, no problem but this is incomplete data.
So I would get 3 instances of Component#1 and 2 instances of Component#2 in your example. And of each the transformation relative to it’s parent.

You have the SUInstancePathRef data field but to fill that path correctly you would need to have the instances and know the parent/child of that instance.

To make the question concrete:
What functions do I need to make the recursive path to go from model->instance->instance->instance? And thus use that to fill a SUInstancePathRef shich in turn will give me a transformation for the complete path.


You are going to multiply the transformations together as you drill into each nesting level.
Use SUTransformationMultiply and then apply the resultant transform to the objects you are exporting (in each level.) Then in the next level down, multiple the previous level’s product result with that level’s local transforms, … etc., … repeat.

I thought that there were SDK samples in the SDK folders ? (There was one that exported to XML, I think.)


And here is a thread that explains doing it in Ruby …