12 Replies Latest reply on Jul 6, 2015 3:45 AM by Qwertyfly...

    Java Script: How select all corner points?

    victorcarbajo

      Java Script: How select all corner points in opened document?

        • 1. Re: Java Script: How select all corner points?
          pixxxel schubser Level 5

          Hi victorcarbajo,

          hmmh?

           

          1. Why and what exactly? (number of corner points or position or corner point kinds)

           

          2. Your illustrator version?

           

          3. A sample document?

           

          4. Are there deep nested grouped groups in your document? Or nested compound paths? Or areas – defined in the appearance palette?

           

          5. What is with hidden paths or clipping paths?

           

          6. How many paths exists in your document?

           

          But anyway – this will give you the number of Path points of the first path item in your document:

          alert (app.activeDocument.pathItems[0].pathPoints.length)
          
          

           

          Have fun

           

          • 2. Re: Java Script: How select all corner points?
            victorcarbajo Level 1

            Example:

            example.png

             

            Result of script:

            result of script.png

            • 3. Re: Java Script: How select all corner points?
              pixxxel schubser Level 5

              Why do you not answers to my questions?

               

              Anyway, this will select the first path point of the first path item in your document:

              app.activeDocument.pathItems[0].pathPoints[0].selected = PathPointSelection.ANCHORPOINT;
              

               

              Have fun

               

              • 4. Re: Java Script: How select all corner points?
                victorcarbajo Level 1

                Thanks, pixxxel schubser, for your answer. Excuse my delay.

                 

                My Illustrator version is 19.0.0.

                 

                There are not nested grouped groups in my document. There are not nested compound paths. Only simple paths with curve and corner points, but the document have a lot of paths. I need to modify corner points together, and then curve points together.

                 

                With best regards.

                • 5. Re: Java Script: How select all corner points?
                  pixxxel schubser Level 5

                  Thanx for your answer.

                  But again:

                  What do you want to do exactly with the selected corner points or selected curved points?

                   

                  The background of this question is: a loop through all path items takes a long time – more path items, more longer! Additional you have to loop through all path points of every path item. The takes again more time! And that's why: What do you want to do exactly with the selected corner points or selected curved points?

                   

                  • 6. Re: Java Script: How select all corner points?
                    victorcarbajo Level 1

                    I need to modify corner points together and curve points together for two reasons:

                     

                    1. When I vectorizing my hand drawings I found a lot of mistake points. I selected the points by hand, but it take a lot of time.

                    2. I explore the possibilities of this two worlds (corner and curve points) when I freely draw in Illustrator.

                     

                    With best regards.

                    • 7. Re: Java Script: How select all corner points?
                      pixxxel schubser Level 5

                      So we will not get. We turn in circles. Imagine, I  am 5 year old and you want to tell me what exactly you are doing.

                       

                      Please define "mistake points".

                      Please give an example file (CS3 or at max CS5 compatible).

                       

                      An automatic vectorization generates countless paths.

                      What criteria do you choose your path points (manually) from? What exactly do you do with the path points after selection???

                      • 8. Re: Java Script: How select all corner points?
                        victorcarbajo Level 1

                        Dear pixxxel schubser,

                         

                        I uploaded a Illustrator CS3 file with "mistake points". Link: mistake_points.ai - Box

                         

                        In this file most points have abnormal behavior. I could correct this abnormal behavior if I could select them and modify with, for example, InkScribe plug-in. Now I make this operation manually.

                         

                        With best regards.

                         

                        PS: Excuse my English, I am Spanish and maybe I do not understand me well.

                        • 9. Re: Java Script: How select all corner points?
                          Qwertyfly... Level 4

                          this may do what you are after.

                           

                          *****Do Not expect this to work on complex paths.*****

                           

                          very tight tolerance set, this can be changed if smooth does not need to be too smooth.

                           

                          //------------------------------------------------------------------------------------
                          //          Select "Sharp" or "Smooth" pathPoints
                          //------------------------------------------------------------------------------------
                          //
                          //          Qwertyfly
                          //          06/07/2015
                          //          Version 1.0
                          //
                          //------------------------------------------------------------------------------------
                          //
                          //          *****Do Not expect this to work on complex paths.*****
                          //
                          //------------------------------------------------------------------------------------
                          //
                          //          Set tolerance here (this is in Radians)
                          var tolerance = 0.0000000001;
                          //
                          //------------------------------------------------------------------------------------
                          var doc = app.activeDocument;
                          var myPoint, angle1, angle2, sel = "";
                          var w = new Window('dialog');
                          var B1 = w.add('button',undefined,"Select Corner Anchors");
                          var B2 = w.add('button',undefined,"Select Smooth Anchors");
                          var B3 = w.add('button',undefined,"Cancel");
                          B1.onClick = function(){sel = "sharp"; goTime();} 
                          B2.onClick = function(){sel = "smooth"; goTime();} 
                          B3.onClick = function(){w.close()} 
                          w.show()
                          function goTime(){
                              w.close();
                              doc.selection = null;
                              for(var i = 0; i < doc.pathItems.length; i++){
                                  for(var j = 0; j < doc.pathItems[i].pathPoints.length; j++){
                                      myPoint = doc.pathItems[i].pathPoints[j];
                                      if(sel == "smooth"){
                                          if(isSmooth()){
                                              myPoint.selected = PathPointSelection.ANCHORPOINT;
                                          }
                                      }else if(sel == "sharp"){
                                          if(!isSmooth()){
                                              myPoint.selected = PathPointSelection.ANCHORPOINT;
                                          }
                                      }else{alert("error");}
                                  }
                              }
                          }
                          function isSmooth(){
                              angle1 = Math.atan2(myPoint.leftDirection[1] - myPoint.anchor[1],myPoint.leftDirection[0] - myPoint.anchor[0]);
                              angle2 = Math.atan2(myPoint.rightDirection[1] - myPoint.anchor[1],myPoint.rightDirection[0] - myPoint.anchor[0]);
                              return(Math.abs((angle1 - angle2)) > Math.PI - tolerance && Math.abs((angle1 - angle2)) < Math.PI + tolerance);
                          }
                          
                          • 10. Re: Java Script: How select all corner points?
                            Qwertyfly... Level 4

                            for your .ai I needed to drop the tolerance to "0.01"

                            then it worked

                            • 11. Re: Java Script: How select all corner points?
                              victorcarbajo Level 1

                              Fantastic! Works!

                               

                              Thanks for your brain, Qwertyfly..., it is a awesome script.

                               

                              With best wishes.