07 Mar

Illustrator Script: Save Selection Coordinates

07. March 2012 by George Profenza

In my previous post I mentioned JS and scripting Adobe Creative Suite applications. Starting with this post, I will release tiny tools written for various CS applications (Flash, Illustrator, Photoshop, etc.) that can make some of the tedious tasks a lot easier.

This week I share a script which allows developers pixel perfect precision when dinamically placing assets based on layouts specified by designers.

script1 This is a pretty simple script: it saves the x,y coordinates of selected objects in Illustrator so they can be used by a developer. The most common scenario is when a designer creates a complex layout with many elements tediously placed, that need to be animated/made interactive. One way to this is to use MovieClips in Illustrator and import them in Flash, then loop through symbols and analyze, which isn’t very flexible.

script2 The script I am sharing now gives you a few options for saving coordinates: either as XML (which can be used with HTML5, Objective-C, Java or other technologies) or as ActionScript 3.0 and the data can either be instantly copied to the clipboard for quick use, or saved to a file so it can be loaded later in an application. You can download the script from as zxp or jsx. files(*).

To use it:

1. Select elements inside an Illustrator document

2. Choose File > Scripts > Save Selection Coordinates

3. Select your options and save !

..as the images show. I’ve also recorded a quick screencast which can be viewed here. Also, the script offers these extra options:

Offset to top left: when selected, the original coordinates are translated so they align with the top left corner (0,0)

Sort from centre: when selected, the order of coordinates is sorted based on the shortest distance to the centre of selection, otherwise, it’s the order in which the assets were placed inside the document.

script3 The small print: zxp is the packaged version of the script so you can just open the file and Extension Manager do it’s job. The annoying thing is I couldn’t find a clean solution for a problem I had with locale and Extension Manager, so the installer will place a lot of copies of the same script just to make sure it works for all locales. If you want to install the script manually, simply download the .jsx file and place it in {Illustrator}/Presets/{locale}/Scripts, where {Illustrator} is the path of your Illustrator installation folder and {locale} is the language/locale used when installing Illustrator. If you have more elegant suggestions for the locale issue when packing scripts, please don’t hesitate to post a comment.

Either way, according to the xkcd graph, this should be handy to someone, at some point :) script4

Subscribe to newsletter:

RSS Feed