sketchucation logo sketchucation
    • Login
    Oops, your profile's looking a bit empty! To help us tailor your experience, please fill in key details like your SketchUp version, skill level, operating system, and more. Update and save your info on your profile page today!
    ⚠️ Important | Libfredo 15.6b introduces important bugfixes for Fredo's Extensions Update

    Use PickHelper to find nested Instances?

    Scheduled Pinned Locked Moved Developers' Forum
    16 Posts 3 Posters 1.1k 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.
    • J Offline
      Jim
      last edited by

      Here's the scenario.

      There is a "Joint" component made of only edges. Using a Tool, I need to be able to get the "global" position of its origin.

      I know how to handle the nested trasnformations, but I thought the PickHelper would give me a list of the nested instances in order, which I can then use for the calculation.


      cubetest.skp

      Hi

      1 Reply Last reply Reply Quote 0
      • J Offline
        Jim
        last edited by

        This is where I think .all_picked is bugged out - it returns an array of the same Instance; where I think it ought to return an array of the nested instances.

        I think .all_picked is returning the correct number of things - it appears to send a ray through the point and picks up the entities both heading into the nest and also picks them up in reverse order as it's exiting the nest.

        Hi

        1 Reply Last reply Reply Quote 0
        • TIGT Offline
          TIG Moderator
          last edited by

          array = pickhelper.path_at(pickhelper.count)
          ❓

          TIG

          1 Reply Last reply Reply Quote 0
          • thomthomT Offline
            thomthom
            last edited by

            @jim said:

            This is where I think .all_picked is bugged out - it returns an array of the same Instance; where I think it ought to return an array of the nested instances.

            I think .all_picked is returning the correct number of things - it appears to send a ray through the point and picks up the entities both heading into the nest and also picks them up in reverse order as it's exiting the nest.

            .all_picked return an array of entities containing the top level entity. You must use .leaf_at to get the deepest item.

            When you use .all_picked after picking a point it'll return all top level entities within the given aperture. If you click on an edge attached to two faces it'll return an array containing the face and edges.

            If the faces and edges are contained within a group/component - then you get an array of the top level entity, which would be the group/component. You then need to use the count of the picked number of entities and traverse the tree of entities picked.

            
            ph = view.pick_helper
            ph.init(x, y, 5) # (!) Allow user to customize pick aperture
            puts "Pick;"
            ph.do_pick x,y
            p ph.all_picked
            puts "> Paths;"
            for i in 1..ph.count
              p ph.path_at(i)
            end
            
            

            Console output from this code after clicking a corner of a cube inside a group:

            ` Pick:
            [#Sketchup::ComponentInstance:0x118a8a18, #Sketchup::ComponentInstance:0x118a8a18, #Sketchup::ComponentInstance:0x118a8a18, #Sketchup::ComponentInstance:0x118a8a18, #Sketchup::ComponentInstance:0x118a8a18, #Sketchup::ComponentInstance:0x118a8a18]

            Paths:
            [#Sketchup::ComponentInstance:0x118a8a18, #Sketchup::Edge:0x117a98b0]
            [#Sketchup::ComponentInstance:0x118a8a18, #Sketchup::Face:0x117a9838]
            [#Sketchup::ComponentInstance:0x118a8a18, #Sketchup::Edge:0x117a97c0]
            [#Sketchup::ComponentInstance:0x118a8a18, #Sketchup::Face:0x117a9748]
            [#Sketchup::ComponentInstance:0x118a8a18, #Sketchup::Face:0x117a96d0]`

            Thomas Thomassen — SketchUp Monkey & Coding addict
            List of my plugins and link to the CookieWare fund

            1 Reply Last reply Reply Quote 0
            • J Offline
              Jim
              last edited by

              Ok, so I need to go through each path until I find the Instance I am looking for?

              If I do that in x-ray mode, it works. But it fails when I turn x-ray off.

              Hi

              1 Reply Last reply Reply Quote 0
              • thomthomT Offline
                thomthom
                last edited by

                @jim said:

                Ok, so I need to go through each path until I find the Instance I am looking for?

                I believe so. Unless there is a shortcut here that I've missed.

                something like

                
                for i in 0...(ph.count)
                  if ph.path_at(i).include?(instance)
                    path = ph.path_at(i)
                    break
                  end
                end
                
                

                @jim said:

                If I do that in x-ray mode, it works. But it fails when I turn x-ray off.

                The output is different?
                The sample output I posted in previous post was with X-Ray off... Not tried with it on.

                (Update with correct indexed.)

                Thomas Thomassen — SketchUp Monkey & Coding addict
                List of my plugins and link to the CookieWare fund

                1 Reply Last reply Reply Quote 0
                • thomthomT Offline
                  thomthom
                  last edited by

                  The docs are outright wrong about the index for the *_at methods. The index does not start at 1 - it start at 0.

                  Thomas Thomassen — SketchUp Monkey & Coding addict
                  List of my plugins and link to the CookieWare fund

                  1 Reply Last reply Reply Quote 0
                  • thomthomT Offline
                    thomthom
                    last edited by

                    @jim said:

                    If I do that in x-ray mode, it works. But it fails when I turn x-ray off.

                    The only difference I see with x-ray mode is that it picks more elements.

                    Thomas Thomassen — SketchUp Monkey & Coding addict
                    List of my plugins and link to the CookieWare fund

                    1 Reply Last reply Reply Quote 0
                    • thomthomT Offline
                      thomthom
                      last edited by

                      My test code


                      tt_picktest.rb

                      Thomas Thomassen — SketchUp Monkey & Coding addict
                      List of my plugins and link to the CookieWare fund

                      1 Reply Last reply Reply Quote 0
                      • J Offline
                        Jim
                        last edited by

                        @thomthom said:

                        @jim said:

                        If I do that in x-ray mode, it works. But it fails when I turn x-ray off.

                        The only difference I see with x-ray mode is that it picks more elements.

                        Yes, I consider it a failure that I (so far) have not been able to pick an Instance that is nested in another Instance unless X-ray is enabled.

                        It must be possible?

                        Hi

                        1 Reply Last reply Reply Quote 0
                        • thomthomT Offline
                          thomthom
                          last edited by

                          So, you have a reference to a ComponentInstance_ And you want to sniff it out using the pickhelper?

                          Maybe just some typo bug in your code?

                          Thomas Thomassen — SketchUp Monkey & Coding addict
                          List of my plugins and link to the CookieWare fund

                          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