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

Illustrator Scripting Help.

New Here ,
Dec 04, 2023 Dec 04, 2023

Copy link to clipboard

Copied

I am looking for a specific script that will center a new artboard under an existing artboad.  The new artboard would be 7 to 10 points wider than the original. Like adding a boarder with an artboard.

I've had a lot of luck creating actions to automate so much of my extremely repetetive file editing, but this is one that still kills my time.  Currently I have to deselect all of the art, switch to artboards, duplicate the original artboard, make the duplicate 7 points wider and taller, align the artboards, select direct selection tool(v), Select all(cmd A), and then center everything on the original artboard.

Any help would be appreciated.

Views

232

Translate

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
Community Expert ,
Feb 22, 2024 Feb 22, 2024

Copy link to clipboard

Copied

LATEST

Hello @Kelly33449404c58c, I just saw your request.

I've created a script that will do as requested. I wasn't sure of the intended purpose, so I've modified it to allow you to change the amount of padding on the new artboard, defaulting to 7 points. It can even use negative values to make the new artboard smaller.

Save the attached file to your computer and change the extension from .txt to .jsx.
In Illustrator, run it using File > Scripts > Other Scripts ..., select the downloaded script and click Open.

Cheers,
Richard

#target illustrator

// This script adds a new artboard to the active document and centres it under the original artboard with a specified border width.
// It is in response to a question on Adobe Community: https://community.adobe.com/t5/coding-corner-discussions/illustrator-scripting-help/td-p/14277937
// Written by Richard Turner-Jones (Community Expert) 

function addCenteredArtboard() {
    var doc = app.activeDocument; // Get the active document

    if (!app.activeDocument) {
        alert("No active document found.");
        return;
    }

    if (doc.artboards.length === 0) {
        alert("The document must have at least one artboard.");
        return;
    }

    // Prompt the user for the border width, defaulting to 7 points
    var borderWidthInput = prompt("Enter the border width.\nPositive numbers will make the new artboard larger.\nNegative numbers will make the new artboard smaller.", "7");
    var borderWidth = parseInt(borderWidthInput, 10);

    // Validate the user input
    if (isNaN(borderWidth)) {
        alert("Invalid input. Please enter a number.");
        return;
    }

    var originalArtboard = doc.artboards[doc.artboards.getActiveArtboardIndex()]; // Get the current active artboard
    var originalRect = originalArtboard.artboardRect; // Get the coordinates of the original artboard

    // Calculate the width and height of the original artboard
    var originalWidth = Math.abs(originalRect[2] - originalRect[0]);
    var originalHeight = Math.abs(originalRect[1] - originalRect[3]);

    // Define the width and height of the new artboard, including the border width
    var newWidth = originalWidth + borderWidth * 2;
    var newHeight = originalHeight + borderWidth * 2;

    // Calculate the position of the new artboard to be centred under the original
    var newX = originalRect[0] - borderWidth;
    var newY = originalRect[1] + borderWidth;
    var newRect = [newX, newY, newX + newWidth, newY - newHeight]; // New coordinates for the new artboard

    // Add the new artboard
    var newArtboard = doc.artboards.add(newRect);

    // Optional: Set the new artboard as the active one
    doc.artboards.setActiveArtboardIndex(doc.artboards.length - 1);

    alert("New artboard added and centred under the original with a border width of " + borderWidth + " points.");
}

// Run the function
addCenteredArtboard();



Votes

Translate

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