Copy link to clipboard
Copied
Is there a way to adjust vertical spacing between Selected artboards by script?
I know 'Rearrange all' can do this, but it affects to all artboards
For a column of artboards, targeted by selecting the items within the artboards:
var spacing = Number(prompt("", "100"));
var doc = app.activeDocument;
// find relevant artboards and items
var artboards = [];
var collection = [];
for (var i = 0; i < doc.artboards.length; i++) {
var bounds1 = doc.artboards[i].artboardRect;
var subcollection = [];
for (var j = 0; j < doc.selection.length; j++) {
var bounds2 = doc.selection[j].geometricBounds;
if ((bounds2[2] > bounds1[0
...
Copy link to clipboard
Copied
For a column of artboards, targeted by selecting the items within the artboards:
var spacing = Number(prompt("", "100"));
var doc = app.activeDocument;
// find relevant artboards and items
var artboards = [];
var collection = [];
for (var i = 0; i < doc.artboards.length; i++) {
var bounds1 = doc.artboards[i].artboardRect;
var subcollection = [];
for (var j = 0; j < doc.selection.length; j++) {
var bounds2 = doc.selection[j].geometricBounds;
if ((bounds2[2] > bounds1[0] && bounds2[0] < bounds1[2]) &&
(bounds2[3] < bounds1[1] && bounds2[1] > bounds1[3])) {
if (!elementIsInArray(doc.artboards[i], artboards)) {
artboards.push(doc.artboards[i]);
}
subcollection.push(doc.selection[j]);
}
}
if (subcollection.length > 0) {
collection.push(subcollection);
}
}
// sort relevant artboards from top to bottom
artboards.sort(function(a, b) {
return b.artboardRect[1] - a.artboardRect[1];
});
// move relevant artboards and items
for (var i = 1; i < artboards.length; i++) {
var ABR1 = artboards[i - 1].artboardRect;
var ABR2 = artboards[i].artboardRect;
var y1 = ABR2[1];
artboards[i].artboardRect = [
ABR2[0], ABR1[3] - spacing,
ABR2[2], ABR1[3] - spacing + (ABR2[3] - ABR2[1])
];
var y2 = artboards[i].artboardRect[1];
for (var j = 0; j < collection[i].length; j++) {
collection[i][j].translate(0, y2 - y1);
}
}
doc.selection = null;
function elementIsInArray(e, a) {
for (var i = 0; i < a.length; i++) {
if (a[i] == e) {
return true;
}
}
return false;
}
NB. Items spanning two artboards will cause unexpected results.
Copy link to clipboard
Copied
It doesn't move artboards with artwork
Copy link to clipboard
Copied
A bug was fixed. Try again.
Copy link to clipboard
Copied
Thank you so much, it will be great time saver
Its working while we select artworks from respective artboards.
But It will be great if can add
1. both to define vertical or horizantal spaceing
2. Respective prompt message
3. Also make enable to work script while selecting artboards in the artboards panel
4. or It should work while select artboards by artboard tool.
Copy link to clipboard
Copied
Artboards are not "selected" the same way that artwork is, at least not in CS6. If they are, this property is not accessible through scripting. You can target an active artboard, but there is one active artboard at a time. Hence the artboards are targeted by selecting the items within them.