Thursday, February 05, 2009

New Script "Select Paths By Size"

I was looking at the "selection" dropdown menu, and noticed that while AI has a "same stroke", and "same fill", it doesn't have a way to select PathItems below a given size.

So I thought, "hey, I can script, this can't be all that hard..."

End result is my first JS4AI for 2009. "Select Paths By Size" simply selects objects smaller (or larger) than a user-supplied threshold of pixels.
(Also note, this is my first script that uses a slider bar.)



I envision it being used to remove small extra bits from a vector-traced image, but I'm sure you can find something cleverer to do with it... Is cleverer a word???
Let me know if you come up with anything cool.



-J

25 comments:

Hugo said...

wow, this sounds excellent, I have used a similar hack in a script I set up - but not so beatifully. Sounds like something perfect for us cartographers! I will post on CartoTalk.com about this.

Greg said...

thanks! this should prove quite useful

John said...

Thanks for the positive feedback Hugo! Nice forum, I'll have to put a few hours aside to check it out. Email me the link to the post if you get the chance, I'd love to see the community response.

Enjoy!

-J

Michael said...

Sounds like an interesting script. When it selects objects below a certain size, does it use total length, area, height, or width?

John said...

Hello Michael,
Good question! Currently, the script averages all the x and y points of an object, then checks distance from absolute center of the object. If any points are farther from center than half the threshold, it is assumed to be larger.

Version 2 will allow you to select the sizing method between this or using the objects height x width.
I can also add an option for selection based on just height or just width alone. I don't want to over-complicate the interface though. Would something like that be useful?

cheers,
-J

Michael said...

Thanks a lot, John. The interface you have looks good, I just wanted to know how you determined the size threshold, and you answered my question. I'll definitely give it a try...

John said...

Awesome, enjoy, and let me know how it goes! :)
-J

Anonymous said...

wow I can now see all the small shapes without going all over the canvas. Thanks.

Anonymous said...

Awesome script! What a timesaver- thank you!!

Anonymous said...

This seems pretty useful, but I've been trying to use it to filter out smaller bits from a live-traced image of sand without much success. It gets going and never seems to finish. I don't know if it would finish if I waited long enough or if I asked it to do something it couldn't so it froze up. I don't know if this is possible, but it would be helpful if this could give some indication of how well it's working while it runs—perhaps it could give a running tally of how many paths it has found so far—just so you know it hasn't locked up.

John said...

Hmmm, I thought I'd added a progress bar. It ::should:: run until completion, and yes, it takes an insanely long time to execute. I recommend setting it running, and then go to lunch, and when you get back, it should be finished. This IS a really slow process, but then again, it's better than doing this by hand. :)
I'll look into the progress bar thing.

Bart said...

really cool script! but is it possible to code a script for selcting paths with a special number of points?

greetz from germany, HP :)

John said...

Really interesting idea Bart. Should be super easy to do. I'd love to hear how you would use such a script.

joebreaker said...

Dear John, thanx a lot for the wonderful scripts shared. However to my utmost regret the script "Select Paths By Size" wouldn't launch on my Illustrator CS5 :( showing the following:

Error 22: Window does not have a constructor. Line: 154
-> var dlg = new Window(dialog', 'Select Path Items:');

Is there any way to fix it?
Regards,
Alex

John said...

It should work in CS5. Weird. Send me an email with what OS you are using it with, I'll see if I can help you troubleshoot.

joebreaker said...

I use Windows 7, 64 bit.

John said...

Thanks for posting joe. I just tried with the same setup, and couldn't repeat the problem. Are you running it from inside illustrators script directory? Try running it through Adobe's included "Extendscript Toolkit" and see if that makes a difference.

joebreaker said...

Dear John,
thanks for the feedback - I've tried to run it thru the Extendscript, however even there it showed mistakes.
Plz, have a look at the provided screenshots:
Toolkihttp://fotoifolder.ru/view_foto/t2f5vwqu6p5o/
http://fotoifolder.ru/view_foto/3-sotg44aftt/
Is there any way to work around it?

Femi said...

GENIUS! Thank you :) Worked perfectly!! Can't wait to check out your other scripts.

Dave said...

man, you saved my day! this is great. thank you so much!!

Dave said...

man, you saved my day! this is great! thank you so much!!

Anonymous said...

Wonderful! Thanks for providing this...will share on FB for my artist friends. I'm using it to select small objects en masse for a project with 2,314 layers (created with a pathfinder action involving complex overlaid geometric shapes). I will be grouping small objects to color them all at once. Saving me hours, thank you!

PS had to save as a .js for CS2

Anonymous said...

any ideas how long this script would take on a file with 55,000 paths.

i'm at about 2hrs and counting and not sure if its just crashed instead?

Thanks

John said...

A long time.. It will vary based on ram, can etc..., but usually it will churn through eventually. You can try selecting parts of the document and running the script to get a benchmark of how fast it is running on your rig.
Let me know how it goes...

John said...

Can == CPU... Autocorrect strikes again...