17 Replies Latest reply on Nov 30, 2015 3:31 PM by Silly-V

    Select object like a "snake"

    Łukasz Markowski Level 1

      Hello,

      is there any way to select object like on image? I mean, start selecting on left side to right, after that go down and start selecting on right to left. JavaScript ofcourse

      sample.jpg

        • 1. Re: Select object like a "snake"
          Silly-V Adobe Community Professional

          If your objects are going to be just like in the image, all perfect same-size shapes neatly lined up in rows & columns, it will be more easier done than if they were different-sized irregular shapes with clipping paths, and not in perfect rows & columns.

          • 2. Re: Select object like a "snake"
            W_J_T Level 4

            Same as in your previous thread about the same thing... The specified item was not found. , what is the point of this? Your provided example does not warrant such a selection.

            • 3. Re: Select object like a "snake"
              Silly-V Adobe Community Professional

              My guess is he wants not just selection order, but actually stacking order. Otherwise yes, Illustrator selections do not care about order of the selection and simply honor stacking order instead.

              • 4. Re: Select object like a "snake"
                Qwertyfly... Level 4

                My guess would also be stacking order, I would say its for some cut path optimization.
                as Silly suggests it would be quite simple if all the shapes are as orderly as the example in the opening post.

                complex shapes in random positions would be much harder.

                 

                • 5. Re: Select object like a "snake"
                  Łukasz Markowski Level 1

                  Yes, I would like make cut optimization, now I make this manually, but sometimes I spend for this to much time. So I thought about script..

                  The most important thing is sequence of path, to go like a "snake".

                  • 6. Re: Select object like a "snake"
                    W_J_T Level 4

                    Qwertyfly... wrote: My guess would also be stacking order, I would say its for some cut path optimization.

                     

                    Ah ok, that gives some clarity then.


                    ( In the past, I was always lucky enough to use rips and cnc routers that did not require such manual user manipulation but rather that were

                    optimized internally with bit travel algorithms. I guess I never much though of it when seeing the above sample picture. )

                    • 7. Re: Select object like a "snake"
                      Qwertyfly... Level 4

                      Try something like this,

                      use the pen tool, click within the first shape, then click within second shape, etc...

                      so now you have a path with a anchor point on each shape in the order you want them.

                       

                      select the path we just drew, and run the script.

                       

                      var doc = app.activeDocument;
                      
                      
                      var sel = doc.selection[0];
                      var items = doc.pathItems;
                      sel.name = "CutOrder";
                      var stacked = doc.layers.add();
                      stacked.name = "Stacked Items";
                      
                      
                      for(var i=0; i<sel.pathPoints.length; i++){
                          var point = sel.pathPoints[i];
                          for(var j=0; j<items.length; j++){
                              var item = items[j];
                              if(item.name != "CutOrder"){
                                  var IB = item.geometricBounds;
                                  if(IB[0]<point.anchor[0] && IB[2]>point.anchor[0] && IB[1]>point.anchor[1] && IB[3]<point.anchor[1]){
                                      item.move(stacked, ElementPlacement.PLACEATEND);
                                      item.name = i+1;
                                  }
                              }
                          }
                      }
                      
                      • 8. Re: Select object like a "snake"
                        Łukasz Markowski Level 1

                        It doesn't work, or I understand it. Paths don't move to layer "stacked items" and still are without order.

                        • 9. Re: Select object like a "snake"
                          williamadowling Level 4

                          Works perfect for me Łukasz.

                           

                          Did you create a path with an anchor point inside of every box? did you have the path selected when you ran the script? did you get any error messages? If yes, what did they say?

                          • 10. Re: Select object like a "snake"
                            Łukasz Markowski Level 1

                            Ok, now I undestand. It works, but for me is still too long way to do this what I want, because I must create path point in every box. I would like to thank you for your time, to help me.

                            • 11. Re: Select object like a "snake"
                              williamadowling Level 4

                              Ok. i have another solution for you that's a little more long-winded. Give me a little bit to adapt it for your needs and i'll get back to you.

                              • 12. Re: Select object like a "snake"
                                Qwertyfly... Level 4

                                I liked this method as you can quickly decide which order you want everything in.

                                 

                                I just drew the cut order line for 35 random items on the page in about 22 seconds.

                                it would take a lot longer then that to arrange them manually.

                                 

                                it would not be hard to write one that does not require the cutOrder line, but it would require regular shapes stacked like cards as you have shown.

                                but if 1 item sits a bit lower then the others on the same line it would mes things up.

                                 

                                is it that you need a point in every shape that you don't like?

                                would it work for you if it just needs to pass across the shape?

                                • 13. Re: Select object like a "snake"
                                  Łukasz Markowski Level 1

                                  Hello, I found another way for this topic. Because in first step I preparing imposition and after that I use these values to create paths anew with correct order. But thank you

                                  • 14. Re: Select object like a "snake"
                                    williamadowling Level 4

                                    Qwerty, i have a script that my team uses every day very similar to what OP is asking for. It's easy enough to set a tolerance so that any items whose top property is within tolerance of a specific placeholder measurement (in this case, that comparative measurement would be the top left square/starting point.

                                     

                                    Łukasz, i'm glad you figured something out. I'm sure everyone would be curious to see what the solution was. Since I'm so close to finishing this, i'll still post my version as well and hopefully between your solution and mine and Qwerty's, everyone will be able to find what they need in the future.

                                    • 15. Re: Select object like a "snake"
                                      Qwertyfly... Level 4

                                      yeah, I get that, I have just always found that when I do cut path ordering I don't trust auto.

                                       

                                      that last thing I want is an external path to cut before an internal, and I am not prepared to lose material or cutting tools due to an auto cut path being incorrect.

                                      but then I can be quite pedantic and I like to set the start point and end point for tool paths, I don't do this in illustrator. I use a dedicated CAM software.

                                       

                                      I'm glad you got something that fits your needs though, and will enjoy looking through williams code, as I'd like to see how he tackled the problem

                                      • 16. Re: Select object like a "snake"
                                        williamadowling Level 4

                                        I'll have something in the morning. I didn't get a chance to finish today. I should preempt my posting of the script with the disclaimer that the idea and general logic was given to me by Silly-V. So I can't take credit for 'tackling the problem'. =P

                                        • 17. Re: Select object like a "snake"
                                          Silly-V Adobe Community Professional

                                          Honestly, I have no idea what you guys are up to, or what kind of cutting machine is at work, so it's just cool to see gridize being put to use in different places. Thanks William!