Get coordinates of nested components

Get coordinates of nested components

Postby Frankn » Wed Jan 11, 2023 2:26 am

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

Postby fredo6 » Thu Jan 12, 2023 8:55 am

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
User avatar
fredo6 
Premium Member
Premium Member
 

Re: Get coordinates of nested components

Postby Frankn » Tue Jan 17, 2023 11:09 pm

@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

Postby fredo6 » Wed Jan 18, 2023 9:43 am

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
User avatar
fredo6 
Premium Member
Premium Member
 

Re: Get coordinates of nested components

Postby Dan Rathbun » Thu May 11, 2023 7:41 pm

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.
    User avatar
    Dan Rathbun 
    PluginStore Author
    PluginStore Author
     

    SketchUcation One-Liner Adverts

    by Ad Machine » 5 minutes ago



    Ad Machine 
    Robot
     



     

    Return to Developers' Forum

    cron

    Who is online

    Users browsing this forum: No registered users and 11 guests