Advertisement


How to align all selected points to a grid?


Question

I'm working with Illustrator to make some icons. I use grid with step = 1px and after I scale/rotate shape elements I want them to automatically align to the grid. I know CS4+ has such an option in transform settings, but I have only CS2 at hand and I was hoping that there's some other way of aligning selected points to the grid (hidden option, script?).

At the moment I'm selecting each point and manually move it up-left them down-right so that it snaps to a grid, but that is VERY slow and prone to mistakes.

Is there a way in Adobe Illustrator CS2 to align all selected points to a grid?

UPDATE: Changed the question details: it should read grid instead of pixel grid (otherwise it was misleading).

1
6
12/13/2013 4:55:00 AM

Accepted Answer

Two possible approaches:


Scripting

The John Wundes script Pixel Align should be a good starting point. I don't have CS2 to test with, but I think it should work with CS2 (the notes seem to say that it's tested and works in CS1, so CS2 should be fine).

The approach the script uses is really simple: it loops through all objects and uses math.round() to round their top, left and where appropriate (i.e. lines), their height and width to the nearest whole number.

You'd need to adapt it so that, for paths, it loops through each point instead of each object. Any script that applies to all points could be a starting point (OP suggested Organify from the same source).


Save as SVG feature

This lets you choose how many decimal places the exported SVG uses to describe things like anchor positions (so people can reduce file size if they don't need super accuracy).

Set it to 0 decimal places, and it'll round anchor points to nearest whole number - i.e. nearest pixel.

So, save as SVG with 0 decimal places, reload, and you should see your image effectively snapped to a pixel grid. Then save as whatever format you need.

Be aware that things like curve angles will also be rounded so check it hasn't mucked up any important details.

Also be aware that snapping to a 1px grid might not give the results you intend when using strokes. For example, a line with a 1px stroke snapped to a 1px grid may give you 0.5px above the line and 0.5px below - you might need to set strokes to inside or outside, or move 1px stroked objects up/down/left/right by 0.5px after they are "snapped" to the grid.

Edit: the asker reports that for them, this almost works, but there are very small differences to the exact positions (presumably due Illustrator having somewhat ropey SVG support).

1
12/16/2013 9:59:00 AM