Question
Script Resize selection Proportionately based on top object dimensions
Figured out a way to loop through a selection and resize everything proportionately to the top object. Is there a way to do this more elegantly? Transformation.DOCUMENTORIGIN seems to be the key, as all objects will be resized relatively, otherwise they are resized based on their own anchors. I reset the view at the end or otherwise it's way off.
function ccCalcPerc(from, to) {
//currently only illustrator
//Times 72 if you're in inches
return (to * 72) / from * 100
}
function aiObjBounds(obj) {
//Get Geometric Bounds
/* Left, Top, Right and Bottom
+ - 1 - +
| |
0 2
| |
+ - 3 - +
*/
var bounds = obj.typename === "Artboard" ? obj.artboardRect : obj.geometricBounds,
left = bounds[0];
top = bounds[1];
right = bounds[2];
bottom = bounds[3];
width = right - left;
height = top - bottom;
props = {
bounds: [left, top, right, bottom],
left: left,
top: top,
right: right,
bottom: bottom,
width: Math.abs(width),
height: Math.abs(height),
obj: obj
};
return props;
}
var aD = app.activeDocument;
d = aiObjBounds(aD.selection[0]);
b = 5;
aSel = aD.selection;
var wPerc = ccCalcPerc(d.width, sizeIN);
var hPerc = ccCalcPerc(d.height, sizeIN);//Add conditional to use height Percentage instead
for (k in aSel) {
//To scale proportionately, the percentage is calculated once and used for both.
aSel[k].resize(wPerc, wPerc, true, true, true, true, 100, Transformation.DOCUMENTORIGIN)
}
aD.selection = null;
aSel[0].selected = true;
app.executeMenuCommand("Fit Artboard to selected Art")
app.executeMenuCommand("fitin");
app.executeMenuCommand("zoomout");
