Created
November 28, 2022 19:24
-
-
Save iconifyit/bf2e1006d37f886fce22938cfbd1826f to your computer and use it in GitHub Desktop.
Function that takes width and height as arguments and resizes all Artboards in an Illustrator document with those dimensions.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function doResizeArtboards(width, height) { | |
if (app.documents.length === 0) { | |
alert("There are no open documents."); | |
return; | |
} | |
var theDoc = app.activeDocument; | |
try { | |
for (i = 0; i < theDoc.artboards.length; i++) { | |
/** | |
* Bounds are always: [left, top, right, bottom] | |
*/ | |
var abBounds = theDoc.artboards[i].artboardRect; | |
/** Legend: | |
* - abctrx = artboard center x | |
* - abctry = artboard center y | |
* - abwidth = artboard width | |
* - abheight = artboard height | |
*/ | |
var left = abBounds[0]; | |
var top = abBounds[1]; | |
var abwidth = abBounds[2] - left; | |
var abheight = top - abBounds[3]; | |
var abctrx = abwidth / 2 + left; | |
var abctry = top - abheight / 2; | |
var left = abctrx - width / 2; | |
var top = abctry + height / 2; | |
var right = abctrx + width / 2; | |
var bottom = abctry - height / 2; | |
theDoc.artboards[i].artboardRect = [ | |
left, | |
top, | |
right, | |
abbottom | |
]; | |
} | |
} | |
catch (e) { alert(e.message) } | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment