round number at x and y cordinate,

Explorer ,
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

246

Likes

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

Advisor , 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
    ];
}

 

Likes

Translate

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

Likes

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
Explorer ,
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

Likes

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
Participant ,
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)

Likes

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.

Likes

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
Participant ,
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 (?)

Likes

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
Advisor ,
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.

Likes

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.

Likes

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
Advisor ,
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
    ];
}

 

Likes

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!

Likes

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.

Likes

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

Likes

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
Advisor ,
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. 

Likes

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
Participant ,
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?

Likes

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.

Likes

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.

Likes

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
Explorer ,
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.

Likes

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.

Likes

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
Explorer ,
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

 

Likes

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.

Likes

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
Participant ,
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

Likes

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

Copy link to clipboard

Copied

basically, select artboards. Object>Make Pixel Perfect

Likes

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.

Likes

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