Skip to content

Instantly share code, notes, and snippets.

@botamochi6277
Created October 9, 2021 02:59
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 botamochi6277/0f2bd842c041ef1a5b30e4581d23385b to your computer and use it in GitHub Desktop.
Save botamochi6277/0f2bd842c041ef1a5b30e4581d23385b to your computer and use it in GitHub Desktop.
Align size for Adobe Illustrator
// script aligning the size of objects with each object origins (center)
// use case: change hole sizes
var dia = new Window("dialog", "unitize object scale", [0, 0, 250, 400]);
dia.pane1 = dia.add("panel", [5, 25, 240, 300], "refelence length");
dia.radi1 = dia.pane1.add("radiobutton", [10, 10, 170, 30], "max. height");
dia.radi2 = dia.pane1.add("radiobutton", [10, 35, 170, 55], "max. width");
dia.radi3 = dia.pane1.add("radiobutton", [10, 60, 170, 80], "min. height");
dia.radi4 = dia.pane1.add("radiobutton", [10, 85, 170, 105], "min. width");
dia.bot1 = dia.add("button", [10, 360, 240, 390], "Run", { name: "ok" });
dia.radi1.value = true;// initial selected radio button
dia.center();
dia.show();
sel = activeDocument.selection;
var heightMax = 0; // temporary maximum of height
var widthMax = 0;// temporary maximum of width
var heightMin = 1e9;// temporary minimum of height
var widthMin = 1e9;// temporary minimum of width
var selSize = [];
// get maximum and minimum lengths
for (i = 0; i < sel.length; i++) {
if (sel[i].clipped) {
selSize[i] = sel[i].pageItems[0];
} else {
selSize[i] = sel[i];
}
// update maximum and minimum lengths
if (heightMax < selSize[i].height) { heightMax = selSize[i].height }
if (widthMax < selSize[i].width) { widthMax = selSize[i].width }
if (heightMin > selSize[i].height) { heightMin = selSize[i].height }
if (widthMin > selSize[i].width) { widthMin = selSize[i].width }
}
// scale object sizes
for (i = 0; i < sel.length; i++) {
if (dia.radi1.value) {
scale = heightMax / selSize[i].height * 100;
} else if (dia.radi2.value) {
scale = widthMax / selSize[i].width * 100;
} else if (dia.radi3.value) {
scale = heightMin / selSize[i].height * 100;
} else {
scale = widthMin / selSize[i].width * 100;
}
sel[i].resize(scale, scale, true, true, true, true, scale, Transformation.CENTER);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment