## Get coordinates of nested components

### Get coordinates of nested components

As the title says... I want to get the coordinates of all nested components.

I've searched but admittedly I don't really understand how transformations work so I might not be searching correctly.

When iterating a component I can get the origin of each nested component but that only returns the coordinates relative to it's immediate parent but not relative to the whole component tree... if that makes sense.

I'm assuming I would have to add each relative component transformation but I have no idea how to do that.
0

Frankn

### Re: Get coordinates of nested components

I guess you talk about world coordinates of nested components, that is coordinates at top level of the model (for instance, which you can use with view.draw method).

If so, then just compose the transformation of each nested level. Transformation composition is the * operation.

For instance, if you wish the world coordinates of a point at a level-3 nested object, just calculate

t = t0 * t1 * t2 * t3, where
• t0 is the identity transformattion, i.e. Geom::Transformation.new()
• tn is the transformation of the Nth group or component (say g), which you get by g.transformation.

This means also that to compute coordinates at level N, you need to know the whole chain of grouponents.
1

fredo6
Premium Member

### Re: Get coordinates of nested components

@fredo thanks for your reply...

So if I understand what you're saying, I need to find all the nested parent components first and there location and from there iterate the nested child components of each nested parent component to get the cumulative location?

Sorry I think I even confused myself!
0

Frankn

### Re: Get coordinates of nested components

Yes. You need to have the list of all components / groups at the top of the nested components.

To find it, it depends on your plugin situation.

For instance, if you pick interactively the nested component, the PickHelper will give you the chain of grouponents.
0

fredo6
Premium Member

### Re: Get coordinates of nested components

fredo6 wrote:For instance, if you pick interactively the nested component, the PickHelper will give you the chain of grouponents.

Expanding upon this use of the PickHelper class ...

This is using the Sketchup::PickHelper#path_at() method. It returns the instance path from the active entities context (for the given index in the list of pick paths.)

To get the full path, you will need to add the pick path to the model's active edit path (if it is not nil.)

Code: Select all
`edit_path = model.active_path ? model.active_path : []full_path = edit_path + pick_path`

Then, you can use a little known method in the InstancePath class to get the transformation ...

Code: Select all
`ipath = Sketchup::InstancePath.new(full_path)trans = ipath.transformation`

See: Sketchup::InstancePath#transformation
0
I'm not here much anymore. But a PM will fire email notifications.

Dan Rathbun
PluginStore Author

### SketchUcation One-Liner Adverts

Ad Machine
Robot

Return to Developers' Forum

## Who is online

Users browsing this forum: No registered users and 7 guests