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

round number at x and y cordinate,

Contributor ,
Aug 23, 2022 Aug 23, 2022

Copy link to clipboard

Copied

Dear all, please help me on this

Need Illustrator scipt to round number at x and y cordinate, so that I can export artboards with exact dimension

 

jkhakase_0-1661250072646.png

 

TOPICS
Scripting

Views

632

Translate

Translate

Report

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

correct answers 1 Correct answer

Guide , Aug 23, 2022 Aug 23, 2022

Thanks @Ton Frederiks.  In which case, this should round the left and top positions of artboards. 

 

var ABs = app.activeDocument.artboards;
for (var i = 0; i < ABs.length; i++) {
    var ABR = ABs[i].artboardRect;
    var dx = Math.round(ABR[0]) - ABR[0];
    var dy = Math.round(ABR[1]) - ABR[1];
    ABs[i].artboardRect = [
        Math.round(ABR[0]), Math.round(ABR[1]), 
        ABR[2] + dx, ABR[3] + dy
    ];
}

 

Votes

Translate

Translate
Adobe
Community Expert ,
Aug 23, 2022 Aug 23, 2022

Copy link to clipboard

Copied

Rearrange All Artboards will align them to round pixel coordinates. You could make an action and record: Object > Artboards > Rearrange All Artboards.

Votes

Translate

Translate

Report

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
Contributor ,
Aug 23, 2022 Aug 23, 2022

Copy link to clipboard

Copied

Rearranging all artboards disrub my visual placement of other artobards as well, looking something will work on selected artboards by the script

Votes

Translate

Translate

Report

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
Engaged ,
Aug 23, 2022 Aug 23, 2022

Copy link to clipboard

Copied

The X and Y cordinates don't actually affect the size of your output. However, you can use the Align tool to align your artboard(s) to another artboard (Select both artboards and the align options appear)

Votes

Translate

Translate

Report

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 ,
Aug 23, 2022 Aug 23, 2022

Copy link to clipboard

Copied

quote

The X and Y cordinates don't actually affect the size of your output. However, you can use the Align tool to align your artboard(s) to another artboard (Select both artboards and the align options appear)


By @chrisg11235813



They do, if they contain fractions, rounding will occur and additional pixels will be generated.

Votes

Translate

Translate

Report

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
Engaged ,
Aug 23, 2022 Aug 23, 2022

Copy link to clipboard

Copied

I always figured that when you move the X or Y positions, the Width and Height shift with the dimentions remaining static (?)

Votes

Translate

Translate

Report

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
Guide ,
Aug 23, 2022 Aug 23, 2022

Copy link to clipboard

Copied

You seem to be using pixels. Illustrator scripting uses points. Converting points to pixels involves multiplying by a repeating decimal and you'll always end up with a decimal. So what you want is not possible.

Votes

Translate

Translate

Report

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 ,
Aug 23, 2022 Aug 23, 2022

Copy link to clipboard

Copied

1 point in Illustrator equals 1 pixel.

The default is 72 ppi which is the same as 72 points in an inch.

No complex conversions are necessary.

Votes

Translate

Translate

Report

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
Guide ,
Aug 23, 2022 Aug 23, 2022

Copy link to clipboard

Copied

Thanks @Ton Frederiks.  In which case, this should round the left and top positions of artboards. 

 

var ABs = app.activeDocument.artboards;
for (var i = 0; i < ABs.length; i++) {
    var ABR = ABs[i].artboardRect;
    var dx = Math.round(ABR[0]) - ABR[0];
    var dy = Math.round(ABR[1]) - ABR[1];
    ABs[i].artboardRect = [
        Math.round(ABR[0]), Math.round(ABR[1]), 
        ABR[2] + dx, ABR[3] + dy
    ];
}

 

Votes

Translate

Translate

Report

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 ,
Aug 23, 2022 Aug 23, 2022

Copy link to clipboard

Copied

Perfect @femkeblanco works like a charm!

Votes

Translate

Translate

Report

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 ,
Aug 23, 2022 Aug 23, 2022

Copy link to clipboard

Copied

And it is a much better solution than Rearranging Artboards, which does not work when there is only a single artboard and it shuffles the artboards around which is (as j.khakase mentioned) not always what you want.

Votes

Translate

Translate

Report

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 ,
Aug 23, 2022 Aug 23, 2022

Copy link to clipboard

Copied

@femkeblanco  I was too quick calling it perfect 😞

It is almost perfect...

It does round the coordinates, but leaves the artwork in the original place, which can give faint anti-aliased pixels at the edges.

Rearrange Artboards has the option to Move artwork with Artboard. If that could be part of the script, it would be perfect.

Screenshot 2022-08-23 at 22.40.43.png Screenshot 2022-08-23 at 22.57.25.png

Votes

Translate

Translate

Report

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
Guide ,
Aug 23, 2022 Aug 23, 2022

Copy link to clipboard

Copied

@Ton Frederiks  Unfortunately, there is no quick fix for this.  Artwork will have to be moved item by item. 

Votes

Translate

Translate

Report

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
Engaged ,
Aug 23, 2022 Aug 23, 2022

Copy link to clipboard

Copied

Would resetting the rulers have the same effect as setting the top left corner to a round number?

Votes

Translate

Translate

Report

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 ,
Aug 23, 2022 Aug 23, 2022

Copy link to clipboard

Copied

@chrisg11235813  Yes, but only for that particular artboard, other artboards can be still off. Rearrange Artboards fixes it for all artboards.

Votes

Translate

Translate

Report

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 ,
Aug 23, 2022 Aug 23, 2022

Copy link to clipboard

Copied

@femkeblanco  That's unfortunate, you were so close to the perfect solution.

Votes

Translate

Translate

Report

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
Contributor ,
Aug 24, 2022 Aug 24, 2022

Copy link to clipboard

Copied

Thank you so much @femkeblanco and all for your valuable comments.

The above pice of code works fine for me. and I get the exact what I want.

Votes

Translate

Translate

Report

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 ,
Aug 24, 2022 Aug 24, 2022

Copy link to clipboard

Copied

Be careful, it is perfect for empty artboards, but check the edges if there is artwork on the artboards.

Votes

Translate

Translate

Report

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
Contributor ,
Aug 24, 2022 Aug 24, 2022

Copy link to clipboard

Copied

LATEST

I just observe one more thing, the artwork doesn't move even respective check mark selected before run the script. and get 1 and half pixcel gap at edges as shown below image

jkhakase_0-1661406276642.png

 

Votes

Translate

Translate

Report

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 ,
Aug 23, 2022 Aug 23, 2022

Copy link to clipboard

Copied

i think you're thinking about mm here. there's no clean conversion from pt to mm.

Votes

Translate

Translate

Report

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
Engaged ,
Aug 23, 2022 Aug 23, 2022

Copy link to clipboard

Copied

It might be too late for this, but here is a video that might work. you can quickly "snap to" the pixel grid. moving artwork with your artboards. 

https://www.youtube.com/watch?v=K-KdA0E4Y64

Votes

Translate

Translate

Report

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
Engaged ,
Aug 23, 2022 Aug 23, 2022

Copy link to clipboard

Copied

basically, select artboards. Object>Make Pixel Perfect

Votes

Translate

Translate

Report

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 ,
Aug 23, 2022 Aug 23, 2022

Copy link to clipboard

Copied

The problem with this is that it not only moves but resizes your artboards. A 540 pixel artboard not aligned to the grid can become a 541 pixel artboard when made pixel perfect.

Votes

Translate

Translate

Report

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