4 Replies Latest reply on Sep 19, 2013 7:56 AM by Prails.deisgn

    Biggest pathItem in a document

    Prails.deisgn

      Hey Guys,

       

      I have a  question that I've been toying with for awhile, is there a way to determine the biggest item in a document using javascript? I haven't even seen anything on it before and I can't find anyhting on it.

        • 1. Re: Biggest pathItem in a document
          CarlosCanto Adobe Community Professional & MVP

          probably nobody has had the need before, try this

           

          - get first pathItem

          - get its length

          - mark it as the the biggest

           

          - get next pathItem

          - get its length

          - compare its length against "the biggest"

          - if bigger, mark it as the biggest, if not ignore it

           

          - continue checking all paths

          • 2. Re: Biggest pathItem in a document
            Prails.deisgn Level 1

            Hey Carlos,

             

            I'm having a tough time with this one, here's what I have so far.

             

            #target illustrator

             

            var doc = app.activeDocument
            var pathCount
            var theBiggest
            
            pathCount=doc.pathItems.length
            
            for (i= 0; pathCount>i;i++){
                thBiggest=doc.pathItems[0]
            
                if (doc.pathItems[i].length > theBiggest) {
                doc.pathItems[i] = theBiggest
                }
            
                else if (doc.pathItems[i].length < theBiggest) {
                   i++
                   }
            
                theBiggest.selected = true;
            
                }
            
            • 3. Re: Biggest pathItem in a document
              CarlosCanto Adobe Community Professional & MVP

              you were close, in your loop you're marking theBiggest as the first path, you need to take that line outside the loop, so theBiggest gets changed

               

              you also have a typo in that same line, thBiggest <- missing an "e"

               

              here's a modified working version

              var doc = app.activeDocument;
              
              
              var pathCount = doc.pathItems.length;
              var theBiggest = doc.pathItems[0];
              
              
              for (i=1; i<pathCount; i++) {
                  if (doc.pathItems[i].length > theBiggest.length) {
                      theBiggest = doc.pathItems[i];
                  }
              } 
              
              
              theBiggest.selected = true;
              
              • 4. Re: Biggest pathItem in a document
                Prails.deisgn Level 1

                Ah duh!

                 

                Ya that totally makes sense now.

                Thanks Carlos