Subscribe To

Saturday, January 07, 2012

Set ALL the Things

Ironically, the use case for this script is very specific, but, read on...
I wanted a script that would allow me to set a bunch of differently sized objects to an exact width.

In illustrator it is easy to scale multiple objects at once, but if they are already placed, and I just want to shrink them to an exact size... I draw a blank.

So I wrote this to fix my problem, but while I was at it, I thought it might be fun to make it a little more flexible. You can use this script to bulk re-size things to specific dimensions. Or, if you're feeling a little more adventurous...

For more advanced (or masochistic) users:
You can also pass functions as values, for instance, assuming you entered:

fillColor

as your attribute,
The following value will set color of all selected objects to red:

Granted, this is super messy, very error prone, and way overkill. If you want to do something this advanced, and you have the skills to write function closures in a prompt, you could easily just write your own custom script, but for quick 'one-off' tasks that don't need a script, maybe this 'advanced use' will come in handy for someone. If not, then maybe it's a good learning exercise.

Simple, or complex, let me know how you use it in the comments. Just remember, the advanced stuff is not required, the script just defaults to 'width,height', so you don't have to do anything complicated to use it.

Update: Script now takes any standard units, so '20mm' and '6ft' are valid values.
Script now also gives you the option to transform objects from their center, rather than defaulting to top,left.

Illustrators JS engine uses px regardless of what the document settings are. A quick workaround is to just enter math formulas instead of values.

If you wanted your objects set to a width of 3 inches, at the value prompt, you could just enter 3*72, because(in illustrator, by default) 1 inch == 72ppi.

If you want to know illustrators pixel value for mm, you can just make a 1x1mm rectangle on the stage, and then switch units (cntrl-alt-shift-U) until pixels are default, and see what that value is. For convenience, it's 2.834646. So, 3mm is 3px * 2.834646. Note this is not an exact conversion, so you may still be a pixel off if you are making really large objects.

In regards to your second question, Illustrator has awesome tools for re-positioning objects, so I didn't feel the need to add it to the script. If you think it would be beneficial, email me a use case, and I'll consider adding it to v2.cheers,-J

Brilliant idea. That use case didn't occur to me. I'll either post an example incorporate that as an option in the next release, or post an example of an inline function to do the trick here in the comments.

David,I have reviewed the code and can see no easy way to implement this without hosing existing flexibility. I will keep looking for an acceptable solution. Can you please email me and let me know what your use case is? It might be worth making into a separate, albeit less flexible script. Thanks-J

This is great - thanks! In the past I've been using Transform Each and busting out the calculator to get the ratio, but this will be much simpler. Since I'm usually working with shapes that will be cut with a laser, I almost always work in physical units, so this is very convenient, too. From my Googling for an alternative to Transform Each, I think many others will be pretty happy with your script as well. Thanks again!

Hello Cristofer,Thanks for posting. Please email me at the address on the top of the script. I've tested the code on my end, and it properly supports decimals for me. How are you using the script, such that decimals aren't working for you?