0 Replies Latest reply on Mar 24, 2016 10:20 AM by Dizz Hicks

    Apply/amend script to work on multiple objects?

    Dizz Hicks

      I need to convert hundreds of objects into perfect circles of a more-or-less equal area to each original object.

      I found the below script but it only works with a single object.

      Can it be amended to apply to all objects selected, or is there a way to apply a script to each selected object individually?

      Thank you!

       

      -----

       

      #target illustrator 

        

      function main() { 

           if (app.documents.length == 0) { 

                alert('Open a document before running this script'); 

                     return; 

           } else { 

                var docRef = app.activeDocument; 

                with (docRef) { 

                     if (pathItems.length == 0) { 

                          alert('No Path Items'); 

                          return; 

                     } else { 

                          var pVB = pathItems[0].visibleBounds; 

                           

                          var pVC = (pVB[2]+pVB[0])/2; 

                          var pHC = (pVB[1]+pVB[3])/2; 

                           

                          var rad = Math.sqrt(pathItems[0].area/Math.PI); 

                           

                          pathItems.ellipse(pHC+rad,pVC-rad,rad*2,rad*2,false,true); 

                           

                          redraw(); 

                     }           

                } 

           } 

       

      main();