6

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).

4
  • 5
    It would be nice if downvoter could explain his motivation, maybe question can be improved? )
    – Kromster
    Dec 12, 2013 at 4:29
  • 2
    It would be nice if now 2 downvoters could explain their positions.
    – Kromster
    Dec 13, 2013 at 11:09
  • No idea what the downvotes were for - this is a really clear question. On some StackExchange sites there's a really ugly undignified trend where some people downvote questions when they don't know the answer... (i.e. any interesting, challenging questions...) I really hope that's not what happened here because I thought we were better than that. Dec 13, 2013 at 11:56
  • 2 downvotes = -4, here's an upvote = +10. You're now at +6.
    – John
    Dec 13, 2013 at 15:27

2 Answers 2

1
+100

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).

11
  • SVG idea sounds nice (CS2 allows decimals from 1 to 7) and after the trick the points are indeed seem to be rounded to the grid, but the alignment is still off by some minor value. Simple check - I select 1 point, press right it jumps 1 cell right, but if I press left instead it jumps 2 cells left. That is the same behavior unaligned points show. So probably what happens is that precision gets lost and points get aligned to something alike 14.9998 or 15.0001 instead of 15.0.
    – Kromster
    Dec 13, 2013 at 12:44
  • If it's a minor value it's likely to be consistent (or, very very similar) for every point - so can't you then move all points at once to get them exactly on the grid? Dec 13, 2013 at 12:53
  • There's another question there, how to see fractional part of points position? When I select any point it's position is shown rounded to closest integer.
    – Kromster
    Dec 13, 2013 at 12:58
  • On a sidenote, it looks like if I'll combine Organify and PixelAlign from the link you have posted, it will provide the exact result I need. Will test that in few hours.
    – Kromster
    Dec 13, 2013 at 13:00
  • It worked almost perfectly! If I may, I want you to focus your answer on scripting and if you can, mention that taking Organify script by John and using Math.round in it produces the desired result! You get my best regards user568458 :)
    – Kromster
    Dec 13, 2013 at 17:10
0

Update:

How about this script. It claims to snap all illustrator objects to the nearest pixel. Not sure if it works on points as well as objects...


Not ideal, but you could save some time by manually type the X or Y position at the top.

If you have a lot of objects sort-of aligned, you could grab them all at once and type in a rounded number into your X or Y field to snap them into position on that axis.

7
  • I tried and manually selecting each point and moving it up-left then down-right is quite faster, but still a total disaster even for 100 points. Still thanks for reply )
    – Kromster
    Dec 13, 2013 at 16:55
  • The Window > Align panel might help also (assuming it exists in CS2)
    – John
    Dec 13, 2013 at 18:52
  • You should check out this thread. It claims to be the Illustrator equiv. of GuideGuide which is a tool in Photoshop to create a grid of guides. Guides have snapping, which might help more than the standard grid.
    – John
    Dec 13, 2013 at 18:55
  • I believe you got my question a bit wrong. I was looking into points alignment to a grid, not objects. I have existing free-form objects (which form up an icon) that I need to scale and rotate sometimes and after I do that I need to keep the nice alignment to a grid (which has a step = 1px) so that upon export I have nice pixel-perfect icons.
    – Kromster
    Dec 13, 2013 at 19:39
  • @KromStern updated answer
    – John
    Dec 13, 2013 at 21:34

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.