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

Script to group artboard contents, centre and resize proportionality

Explorer ,
Jan 31, 2023 Jan 31, 2023

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!

TOPICS
Scripting
705
Translate
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 , Mar 02, 2023 Mar 02, 2023

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]
...
Translate
Adobe
Explorer ,
Mar 02, 2023 Mar 02, 2023

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?

Translate
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 ,
Mar 02, 2023 Mar 02, 2023

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);
}

 

Translate
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
Explorer ,
Mar 06, 2023 Mar 06, 2023

Amazing, thank you @femkeblanco 🙌🏼

Translate
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
New Here ,
May 02, 2024 May 02, 2024
LATEST

Thank you so much for this @femkeblanco!

Worked perfectly 🙂 

Translate
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