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

    Use PickHelper to find nested Instances?

    Scheduled Pinned Locked Moved Developers' Forum
    16 Posts 3 Posters 994 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

      How do I use a PickHelper to find a ComponentInstance which is nested several levels deep inside other Instances?

      Hi

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

        PickHelper.path_at
        You'd have to find the index for the instance though.

        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

          Thanks Thom. I guess I really don't understand what the PickHelper methods are supposed to do.

          I had first tried .all_picked thinking it would return an Array of all elements in the pick (like the docs state.) What I am actually seeing is an array of all the exact same Instance (the top-level one.) Can that be correct ❓

          Hi

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

            You know what - I'm a wee bit confused myself right now when I try it out.
            If you click on loose geometry, at a vertex corner you get edges and faces attached to the vertex.
            But there is something odd with components and groups...

            hmm...
            or maybe.... If you click on an edge inside a group, do you then get an array of three? if you iterate 1 - 2 as index and use path_at or leaf_at - do you then get different results?

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

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

              The leaf_at returns the 'deepest picked entity' - i.e. a face
              You could then get its container / parent.
              You could also have found that face from picked_face ?
              The pickhelper returns a list of 'picked objects' and its methods then let you sort through them ?

              TIG

              1 Reply Last reply Reply Quote 0
              • 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