How to get the parent ComponentInstance of a child ComponentInstance

So I have a ComponentInstance from the scene/model, and its parent type is ComponentDefinition, how can I get the actual parent entity and not the definition in which it is contained ?
Example: make a Box1, make it component, inside this make another Box2, make it component.
Box2.parent.typename is ComponentDefinition and not ComponentInstance.
I know that ComponentDefinition has instances member, but that doesnt help me.
Any idea?
PS: Basically I am trying to find out the world transformation of any ComponentInstance I choose.

Make a new Tool which uses a pickhelper
as the user picks the object.
Its listed ‘pick records’ can show picked_elements [not edges/faces] under the picked point.
Its transformation_at() can then returns those items by key, so you can step through, and collect the nested instances, groups etc, and most usefully their transformations…

You need to do a few tests to understand what happens…

Yes, but the problem is that I try to check what things modify, for sync with external app, I do catch the onElementModified, and that gets me ComponentInstance(s).
Now I need to find its world transform, but this instance can also be a part of another instance in a component definition, which is unique to the scene, so I really dont know what clone of the actual component definition tree modified :), if you understand me.
The problem is that SU doesnt provide me with info about what I see in the scene. It draws or keeps internal the transforms for the objects I see in the scene.
For example I make a box component which have another box component inside it. I replicate it 10 times in the scene.
If I try to find a specific inner box’s world transform I need to walk the hierarchy from active model up to the component instance inside the … component instance of the parent.
When onElementModified or onChangeEntity triggered I only get the actual data changes for the component definitions, not the actual scene instances that I see. In a regular 3D package, or 3D engine, you keep all the instance transforms of all the things you see in the scene, usually. SU is very data driven, it draws on the go, maybe it keeps the world transform temporary when it draws the definitions…

After examining the output from a pick helper tool, it becomes apparent that grouped objects not only re-use the fundamental drawing elements as part of their definition, but can re-use other grouped objects. If you have a component inside of another, there may not be a single parent, but multiple ones. The most outer ones are separate instances, but the inner ones may be being reused, just like faces and edges can be re-used inside grouped objects. Sketchup’s “Face” class doesn’t have a parent method that states if it is inside a component, and what component it is in. It could be in multiple components.

If you have a reference to a specific inner box (which Sketchup’s built-in select tool and a Ruby statement could tell you), and you know that it is the only one in the entire model, you can recursively go through all of the objects in the model searching for it. As you go inside of other components searching for it, you can keep track of each transformation.

A truly MV paradigm :).
Anyway I gave up, I will just sync the scene to my app in other ways. Will use model.definitions and so on.

SU is not really ready for realtime sync with other apps. You need to build a lot of code around it to make it feasable for that.

SketchUp itself isn’t “real-time”, but transaction-based. Take any drawing tool for example, the geometry isn’t actually added to the model until the user finishes the operation. A face from the rectangle tool is not added until the user finishes the 2nd click. A Group isn’t actually moved until the user finishes the Move tool operation. A lot can happen between the time a user starts an operation and SketchUp finishes it.

You may need to write your own tools if you need to tell other software finer details of the user’s actions.

Is there other software that support realtime sync? And what does that mean?

No DCC tool supports “realtime sync”, I was talking more of the scene graph structure itself.
In other tools you have a clear graph, nodes, even the instance nodes of the instances inside an instance (!) :slight_smile:
Also you have the means to get the world and local matrices for the nodes. These transformations are also static, they do no change as it does in SU, where when you edit a component the transformation will report either local or 0,0,0, which is a bit odd, but anyway SU is way different from any other app I have seen in terms of API/scene organization.
And yes, I need to write a lot of code to be able to do some simple stuff :slight_smile: like getting a world transform for an instance.