Skip to content

Instantly share code, notes, and snippets.

@iconifyit
Created November 28, 2022 20:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save iconifyit/600fdd04998c4cdb9f1cbbc3bcb52b22 to your computer and use it in GitHub Desktop.
Save iconifyit/600fdd04998c4cdb9f1cbbc3bcb52b22 to your computer and use it in GitHub Desktop.
Example Illustrator script to create a pop-up with dropdown list to change artboards to pre-selected sizes.
var docRef = app.activeDocument;
var dialog = new Window("dialog");
dialog.text = "Escolha Cilindro";
dialog.preferredSize.width = 400;
dialog.orientation = "column";
dialog.alignChildren = ["left", "top"];
dialog.spacing = 10;
dialog.margins = 16;
var _list_array = [
"130,18",
"133,35",
"136,53"
];
var _list = dialog.add(
"dropdownlist",
undefined,
undefined, {
name: "_list",
items: _list_array
}
);
_list.selection = 0;
_list.alignment = ["left", "top"];
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) }
}
dialog.onChange = function() {
var _selected = _list.selection.text;
var dims = _selected.split(",");
var width = dims[0];
var height = dims[1];
doResizeArtboards(width, height);
}
dialog.show();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment