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

Duplicate artboards several times using a script

Explorer ,
Apr 17, 2022 Apr 17, 2022

 

Hello, I need a script that will duplicate artboards. It's important that as soon as I run the script a window will open asking how many times to duplicate. If you enter 0, then nothing will be duplicated.

TOPICS
Scripting
932
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

Community Expert , Apr 17, 2022 Apr 17, 2022

Hi,

Try follwing snippet

 

#target illustrator
function duplicateArtboard() {
    var dlg = new Window("dialog", "Duplicate Artboard");

    row = dlg.add('group', undefined, '');
    row.add('statictext', undefined, "Times: ");
    var timesInput = row.add('edittext', undefined, "");

    var duplicateButton = row.add('button', undefined, 'Duplicate', {
        name: 'Duplicate'
    });

    duplicateButton.onClick = function () {
        var _numberOfTimes = Number(timesInput.text);
        if
...
Translate
Adobe
Community Expert ,
Apr 17, 2022 Apr 17, 2022

Hi,

Try follwing snippet

 

#target illustrator
function duplicateArtboard() {
    var dlg = new Window("dialog", "Duplicate Artboard");

    row = dlg.add('group', undefined, '');
    row.add('statictext', undefined, "Times: ");
    var timesInput = row.add('edittext', undefined, "");

    var duplicateButton = row.add('button', undefined, 'Duplicate', {
        name: 'Duplicate'
    });

    duplicateButton.onClick = function () {
        var _numberOfTimes = Number(timesInput.text);
        if (_numberOfTimes != 0) {
            for (var i = 0; i < _numberOfTimes; i++) {
                var doc = app.activeDocument;
                var thisBoardIndex = doc.artboards.getActiveArtboardIndex();
                var thisBoard = doc.artboards[thisBoardIndex];
                var thisRect = thisBoard.artboardRect;
                var lastBoard = doc.artboards[doc.artboards.length - 1];
                var lastRect = lastBoard.artboardRect;
                doc.selectObjectsOnActiveArtboard();
                app.copy();
                var newBoard = doc.artboards.add(thisRect);
                var offsetH = 20;
                newBoard.artboardRect = [
                    lastRect[2] + offsetH,
                    lastRect[1],
                    lastRect[2] + offsetH + (thisRect[2] - thisRect[0]),
                    lastRect[3]
                ];
                newBoard.name = thisBoard.name + " copy";
                app.executeMenuCommand("pasteFront");
                doc.selection = null;
            }
        }
        dlg.close();

    };
    dlg.show();
};
duplicateArtboard();

 

Best regards
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 ,
Apr 17, 2022 Apr 17, 2022
LATEST

Thank you!
Now I have another request.
I need to insert cards that will fill the entire height of the sheet (30 cm)
Is it possible to give the value of a desired number of cards, and the script will duplicate to a maximum of cards that go in height?

I will give 3 examples for you to understand:

1. If I need 5 cards 5 cm high, the script will duplicate me 6 cards, because 5 * 6 is 30.

2. If I need 3 cards 5 cm high, the script will also duplicate me 6 cards because 5 * 6 is 30.

3. Screen Shot 2022-04-17 at 16.19.32.pngIf I need 7 cards 5 cm high, the script will duplicate me 12 cards.
Attached is a diagram for example 3.

That is, always take advantage of the height of the sheet
To the maximum.

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