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.

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 level3 nested object, just calculate
t = t0 * t1 * t2 * t3
, wheret0
is the identity transformattion, i.e.Geom::Transformation.new()
tn
is the transformation of the Nth group or component (sayg
), which you get byg.transformation
.
This means also that to compute coordinates at level N, you need to know the whole chain of grouponents.

@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!

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. 
@fredo6 said:
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
.)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 ...ipath = Sketchup;;InstancePath.new(full_path) trans = ipath.transformation
Advertisement