Quantcast
Channel: Adobe Community : Popular Discussions - Illustrator Scripting
Viewing all articles
Browse latest Browse all 12845

JS select all almost equal shapes to selected one. Why it affects only on paths but not on compound paths?

$
0
0

Hi guys!

 

I'm new in JS and wrote a script for selection of all almost equal shapes (by size) to the one I select before running a script. I work with svg files mostly and precision of dimensions varies depending on many things, shapes which look like equal are not those and have very small difference like 0.005 px in length or width/height.

I know about existent script SelectPathsBySize but it's too heavy (works really slow) and doesn't fit to my needs. So I decided to write my own.

It works well on paths (when some path is selected script selects all almost equal path in my design) but when I select compound path the script returns nothing (given there are many almost equal compound paths in the design).

Here is the script:

 

var myDoc = app.activeDocument; 

var shape = app.activeDocument.selection[0];

 

for (i=0 ; i< myDoc.pageItems.length; i++) 

     { 

  var allShapes = myDoc.pageItems[i] 

  var diff = Math.abs( shape.length - allShapes.length )

  var diff2 = Math.abs( shape.width - allShapes.width );

          if( diff < 0.015 && diff2 < 0.01 )

                         allShapes.selected = true; 

                    } 

     } 

 

app.redraw();

 

I'd be very appreciated for any tips/suggestions how to make it work for compound paths as well.

Thanks in advance!


Viewing all articles
Browse latest Browse all 12845

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>