Skip to main content
sinrise
Known Participant
October 6, 2011
Question

Select all objects with a certain shape or dimension

  • October 6, 2011
  • 1 reply
  • 1552 views

I'm trying to automate several repetitive actions in Illustator CS3. I need to be able to select all paths of a certain dimension. In this case, it's a circluar path 1.86 pt x 1.86 pt. with no stroke and 100% black fill. Other objects have the same fill color so selecting the same fill color won't work. (They are not actual ellipses either because they were created in another application, but they are all the same size and uniform dimensions.)

Is there a way to target all objects within a document of particular dimensions?

Thanks!

This topic has been closed for replies.

1 reply

Inspiring
October 6, 2011

Sure there are a whole bunch of ways that you could go about this… How many criteria you need to match and how accurate would be down to your art… As a quick and dirty method, may be being a close enough circumference and number of points would suffice…?

#target illustrator

var doc = app.activeDocument;

var items = doc.pathItems;

var found = Array();

for ( var i = 0; i < items.length; i++ ) {

 

          if ( items.pathPoints.length == 4 ) {

 

                    if ( items.length.toFixed( 1 ) == ( Math.PI * 1.86 ).toFixed( 1 ) ) {

 

                              found.push( items );

 

                    };

 

          };

          doc.selection = found;

 

};

sinrise
sinriseAuthor
Known Participant
October 7, 2011

Thanks very much. I get mixed results with this. The first time I pasted it into the JS console in ExtendScript Toolkit 2 and it selected some of the circles, but not all. I savd it and tried to load into Illustrator but when I load it locks up the application and I have to end-task. I tried pasting it into the JS console again but I keep getting "too many closing braces" error... weird.

I realzied the geometry is not accurate. I changed my units to pixels and the circles aren't exactly uniform. Some are 1.86 px sqaure and some are 1.859 x 1.86 so that's probably why it wasn't selecting all. But, why am I getting inconsistent results with the console and why does it cause AI to stop responding, I wonder?

Inspiring
October 8, 2011

Hum… Im not sure about that Im using the ESTK 4.1.25 (CS5) and I did test before posting… It tells me the syntax is fine… The difference in size I would doubt is the problem… Taking the value to one decimal place with toFixed(1) should have allowed for a 'slight deviation'… these are small items… may be the user selecting one item and the script looking for a property like 'area' would work better. Script could look for +- a given value but without seeing your file I have no idea what that would encompass… I go have a look…