sketchucation logo sketchucation
    • Login
    πŸ€‘ SketchPlus 1.3 | 44 Tools for $15 until June 20th Buy Now

    Get coordinates of nested components

    Scheduled Pinned Locked Moved Developers' Forum
    5 Posts 3 Posters 4 Views 3 Watching
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • F Offline
      Frankn
      last edited by

      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.

      1 Reply Last reply Reply Quote 0
      • fredo6F Offline
        fredo6
        last edited by

        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 Reply Last reply Reply Quote 0
        • F Offline
          Frankn
          last edited by

          @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! πŸ˜•

          1 Reply Last reply Reply Quote 0
          • fredo6F Offline
            fredo6
            last edited by

            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.

            1 Reply Last reply Reply Quote 0
            • Dan RathbunD Offline
              Dan Rathbun
              last edited by

              @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
              
              

              See: Sketchup::InstancePath#transformation

              I'm not here much anymore.

              1 Reply Last reply Reply Quote 0
              • 1 / 1
              • First post
                Last post
              Buy SketchPlus
              Buy SUbD
              Buy WrapR
              Buy eBook
              Buy Modelur
              Buy Vertex Tools
              Buy SketchCuisine
              Buy FormFonts

              Advertisement