Skip to content

Instantly share code, notes, and snippets.

@iconifyit
Created November 28, 2022 19:24
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save iconifyit/bf2e1006d37f886fce22938cfbd1826f to your computer and use it in GitHub Desktop.
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.
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