Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

A script to snap all anchor points to pixel grid?

New Here ,
Jul 17, 2015 Jul 17, 2015

Similar to the Align to Pixel Grid except for points not objects. Doesn't sound like it would be that difficult - simply rounding up the position to the nearest whole pixel.

TOPICS
Scripting
1.5K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Adobe
Mentor ,
Jul 17, 2015 Jul 17, 2015

blackmath wrote: Doesn't sound like it would be that difficult - simply rounding up the position to the nearest whole pixel.

You're right, it's not, so what do you have so far?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jul 18, 2015 Jul 18, 2015

From a non-scripter's perspective I thought rounding up the position of anchor points to the nearest whole number would be quite straightforward. It sounds simple in principle, but I'm guessing the fact that there are no scripts out there that do such a thing is evidence to the contrary.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Mentor ,
Jul 19, 2015 Jul 19, 2015

@ pixxxel what was the "diffArray" used for in your code? To compare before and after?

blackmath wrote:

... but I'm guessing the fact that there are no scripts out there ...

[^ So back to that point] I think it's more about the fact there is a lack of need for one, not the lack of ability to make one. 😉 I was gonna suggest earlier that it seems more of a workflow understanding issue (please don't take it wrong, not meant to offend) than a need for a script. You can find many articles about pixel perfect, pixel hinting, etc.. design in Illustrator.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jul 19, 2015 Jul 19, 2015
LATEST

W_J_T schrieb:

@ pixxxel what was the "diffArray" used for in your code? To compare before and after? …

Oh sorry. It's only a part from my another script that I forgotten to clean.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jul 19, 2015 Jul 19, 2015

IMHO this seems to be no good idea!

blackmath schrieb:

Doesn't sound like it would be that difficult - simply rounding up the position to the nearest whole pixel.

Yes. For one simple object like a rectangle (pointType: corner) this might be so. Perhaps with an ellipse this could be easy also.

But for a complex file with hundreds and thousands of paths? How much time do you have? And additional: Are there really paths only or more paths from appearance panel or effects or brushes and so on? With script elaborately or even impossible.

Furthermore:

What is if you have had paths with small dimensions like a vectorized font in your document? This can't be give you a good result - never!

Here an example with a 20pt letter c in Myriad Pro (red is original vectorized letter and black [in Modus difference = blue] the result after aligning)

pathPointsAlignToPixelgrid.png

But anyway - for the beginningyou can try something like this:

// pathPointsSnapToPixelGrid.jsx

// use it on your own risk

// required: an opened document with one pathItem

// regards pixxxelschubser

var aDoc = app.activeDocument;

var pP = aDoc.pathItems[0].pathPoints;

var diffArray = [];

var anArray = [];

var leftArray = [];

var rightArray = [];

for (i=pP.length-1; i >=0 ; i--) {

    anArray = [Math.round(pP.anchor[0]), Math.round(pP.anchor[1])];

    leftArray = [

    pP.leftDirection[0] - (pP.anchor[0] - Math.round(pP.anchor[0])),

    pP.leftDirection[1] - (pP.anchor[1] - Math.round(pP.anchor[1]))

    ];

    rightArray = [

    pP.rightDirection[0] - (pP.anchor[0] - Math.round(pP.anchor[0])),

    pP.rightDirection[1] - (pP.anchor[1] - Math.round(pP.anchor[1]))

    ];

    aDoc.pathItems[0].pathPoints.anchor = anArray;

    aDoc.pathItems[0].pathPoints.leftDirection = leftArray;

    aDoc.pathItems[0].pathPoints.rightDirection = rightArray;

     }

Have fun and give a response please

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Mentor ,
Jul 19, 2015 Jul 19, 2015

Hi pixxxel schubser,

I was concerned with the same thing concerning distortion possibilities.

@ blackmath,

For better understanding, can you please explain further what your intent / need / use for this is? As well as provide us an example screen shot / or file of the type of typical things it will be used with.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jul 19, 2015 Jul 19, 2015

I've been designing simple logos and ensuring that each anchor point is positioned on a pixel boundary. As soon as I scale up the logo the points no longer align to the pixel grid. I don't really understand how that's possible if it's a proportional increase. That's what led to this request.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jul 19, 2015 Jul 19, 2015

simple maths

E.g. a rectangle with 4px × 5px will be scaled, say to 6px in x proportional increase. The result in y = 5px * factor1,5 = 7,5px

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jul 19, 2015 Jul 19, 2015

I'm incredibly stupid.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jul 19, 2015 Jul 19, 2015

Better: lost in minds.

One question:

did you try the script snippet meantime?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines