Copy link to clipboard
Copied
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");
Copy link to clipboard
Copied
Bonjour @_wckdTall_
Je n'ai pas compris le sens de cette fonction ?
function ccCalcPercPour la suite, je pense que le script qui suit peut correspondre à votre demande
// JavaScript Document for Illustrator
// de elleere Landry René
// Pour échelle 2:1 tapez 2
// Pour 1:2 tapez 0.5
function test() {
if (!selection) return;
var wPerc, hPerc;
wPerc = hPerc = 2;
var T = Transformation.DOCUMENTORIGIN;
var doc = activeDocument;
var aSel = app.selection;
var origin = doc.rulerOrigin;
doc.rulerOrigin = [0,0];
var rep = prompt("Echelle ?\rwPerc,hPerc",wPerc+","+hPerc);
rep = rep.split(",");
wPerc = rep[0]*1;
hPerc = rep[1]*1;
cperc = (wPerc+hPerc)/2;
var Rects = aSel[0].geometricBounds;
doc.rulerOrigin = centre(Rects);
for (var k = 0; k < aSel.length; k++) {
aSel[k].resize(wPerc*100, wPerc*100, true, true, true, true, cperc*100, T);
}
doc.rulerOrigin = [0,0];
doc.rulerOrigin = origin;
}
if (app.documents.length) test();
// -------
function centre(Bounds)
{return [Bounds[0]+(Bounds[2]-Bounds[0])/2,Bounds[3]+(Bounds[1]-Bounds[3])/2];}
// -------René
Copy link to clipboard
Copied
Thanks! Setting the ruler origin did not change the results.
To answer your question. The purpose of the function is to resize all selected art, to the width of a specific path. It has been helpful resize based on dielines maintain layering, and not have to clip everything into one group.
Copy link to clipboard
Copied
Sergey Osokin generously provides a script called "Resize to Size". You may give it a try.
Copy link to clipboard
Copied
Tried it, works quite well. This assumes the items in the selection are grouped. What I'm proposing, is sizing all of a selection, paths etc, based on a specific shape. Determining a percentage for all based on a single path.
I really like what was done with the radio buttons and alignment. I tried to make a small selection like that before and kept getting text overlap.
Thanks for sharing!
Find more inspiration, events, and resources on the new Adobe Community
Explore Now