Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
0

How to adjust vertical spacing between Selected artboards by script?

Engaged ,
Jun 27, 2023 Jun 27, 2023

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

jkhakase_0-1687923607007.png

 

TOPICS
Scripting

Views

512
Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Guide , Jun 28, 2023 Jun 28, 2023

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
...

Votes

Translate
Adobe
Guide ,
Jun 28, 2023 Jun 28, 2023

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.

Votes

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
Jun 28, 2023 Jun 28, 2023

Copy link to clipboard

Copied

It doesn't move artboards with artwork

Votes

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guide ,
Jun 28, 2023 Jun 28, 2023

Copy link to clipboard

Copied

A bug was fixed. Try again.

 

1.gif

Votes

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
Jun 29, 2023 Jun 29, 2023

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.

Votes

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guide ,
Jun 29, 2023 Jun 29, 2023

Copy link to clipboard

Copied

LATEST

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. 

Votes

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines