Copy link to clipboard
Copied
Hi,
I've seen a script to help with portions of this, here. However, I was wondering if there's a script to work through all artboards and:
1. group artboard contents
2. centre
3. size proportionality (from the middle) to the artboard size (whichever vertically or horizontally) meet the size first
Possible?
Thanks!
1 Correct answer
This should do what you want (iterate artboards, group, centre and resize):
var doc = app.activeDocument;
var ABs = doc.artboards;
for (var i = 0; i < ABs.length; i++) {
app.selection = null;
ABs.setActiveArtboardIndex(i);
doc.selectObjectsOnActiveArtboard();
// group
var o = doc.groupItems.add();
for (var j = 0; j < app.selection.length; j++) {
app.selection[j].moveToEnd(o);
}
var b1 = o.visibleBounds;
var w1 = b1[2] - b1[0];
var h1 = b1[1] - b1[3]
...
Explore related tutorials & articles
Copy link to clipboard
Copied
I've kind of managed to put this together using some smaller scripts and actions within a single action. The only thing I'm unable to figure out is how to repeat the action across the number of artboards. Is there a couter scrtipt out there, I've looked but can't find one?
Copy link to clipboard
Copied
This should do what you want (iterate artboards, group, centre and resize):
var doc = app.activeDocument;
var ABs = doc.artboards;
for (var i = 0; i < ABs.length; i++) {
app.selection = null;
ABs.setActiveArtboardIndex(i);
doc.selectObjectsOnActiveArtboard();
// group
var o = doc.groupItems.add();
for (var j = 0; j < app.selection.length; j++) {
app.selection[j].moveToEnd(o);
}
var b1 = o.visibleBounds;
var w1 = b1[2] - b1[0];
var h1 = b1[1] - b1[3];
var b2 = o.geometricBounds;
var w2 = b2[2] - b2[0];
var h2 = b2[1] - b2[3];
// centre
var ABR = ABs[i].artboardRect;
o.position = [(ABR[0] + ((ABR[2] - ABR[0]) / 2)) - (w2 / 2),
(ABR[1] + ((ABR[3] - ABR[1]) / 2)) + (h2 / 2)];
// resize
w = doc.width - (w1 - w2);
h = doc.height - (h1 - h2);
var f = (w1 > h1) ? w / w2 * 100 : h / h2 * 100;
o.resize(f, f);
}
Copy link to clipboard
Copied
Amazing, thank you @femkeblanco 🙌🏼
Copy link to clipboard
Copied
Thank you so much for this @femkeblanco!
Worked perfectly 🙂

