Resize all Artboards and its Artwork

Community Beginner ,
May 22, 2019 May 22, 2019

Copy link to clipboard

Copied

Hello, I'm using this script to scale up all my Artboards but the artwork (object on active artboards wont scale up). In there any way to do it?

#target Illustrator

//  script.name = resizeArtboards_CS4andUp.jsx;

//  script.description = resizes all artboards;

//  script.requirement = one document with at least one artboard;

//  script.parent = carlos canto // 11/4/12;

//  script.elegant = false;

if (app.documents.length > 0) {

        //alert("more than 0");

                    var idoc = app.activeDocument;

        var title = "Resize All Artboards";

        var width = Number(Window.prompt ("Enter New Artboard Width in points", 30, title));

        var height = Number(Window.prompt ("Enter New Artboard Height in points", 30, title));

    for (i=0; i<idoc.artboards.length; i++) {

        var abBounds = idoc.artboards.artboardRect;// left, top, right, bottom

        var ableft = abBounds[0]; // 0

        var abtop = abBounds[1]; // 612

        var abwidth = abBounds[2] - ableft; // 792 // width

        var abheight = abtop- abBounds[3]; // 0 // height

        var abctrx = abwidth/2+ableft;

        var abctry = abtop-abheight/2;

        var ableft = abctrx-width/2;

        var abtop = abctry+height/2;

        var abright = abctrx+width/2;

        var abbottom = abctry-height/2;

        idoc.artboards.artboardRect = [ableft, abtop, abright, abbottom];

    }

}

else  {

        alert ("there are no open documents");

}

TOPICS
Scripting

Views

870

Likes

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

correct answers 1 Correct answer

Community Beginner , May 23, 2019 May 23, 2019
Here you go#target IllustratorrequiredABsize = prompt( 'Scale artboards to what square size?\nRemember this number to create enough space between your scaled artboards in the next step.\n\nThis script uses \"Scale Strokes and Effects\" for you.\n\n', '500', 'Select artboard area');// Make sure the user generates enough space between the artboardsapp.executeMenuCommand("ReArrange Artboards");var activeDoc = app.activeDocument;var TotalArtboards = activeDoc.artboards.length;  var originalOrigin = ...

Likes

Translate

Translate
Community Beginner ,
May 23, 2019 May 23, 2019

Copy link to clipboard

Copied

LATEST

Here you go

#target Illustrator

requiredABsize = prompt( 'Scale artboards to what square size?\nRemember this number to create enough space between your scaled artboards in the next step.\n\nThis script uses \"Scale Strokes and Effects\" for you.\n\n', '500', 'Select artboard area');

// Make sure the user generates enough space between the artboards

app.executeMenuCommand("ReArrange Artboards");

var activeDoc = app.activeDocument;

var TotalArtboards = activeDoc.artboards.length; 

var originalOrigin = activeDoc.rulerOrigin;

for (var i = 0 ; i < TotalArtboards; i++){

    var _artboards = activeDoc.artboards;

    var abActive   = _artboards;

    var abProps    = getArtboardBounds(abActive);

    var scale      = findRequiredScale(abProps);

// abActive   = activeDoc.artboards[ activeDoc.artboards.getActiveArtboardIndex() ];

    activeDoc.artboards.setActiveArtboardIndex(i);

// alert(i);

    app.selection = [];

    // app.executeMenuCommand ('deselectall');

    app.executeMenuCommand ('selectallinartboard');

    var selection = activeDoc.selection;

    var artboardRight = abActive.artboardRect[2];

    // Get the Height of the Artboard

    var artboardBottom = abActive.artboardRect[3];

    var artboardX = abActive.artboardRect[0];

    var artboardY = abActive.artboardRect[1];

var horziontalCenterPosition = (artboardRight+(-1*artboardX))/2;

var verticalCenterPosition = (artboardY-(artboardBottom))/2;

//alert(app.activeDocument.rulerOrigin+"\n left "+artboardX+"\ntop "+artboardY+"\nright "+artboardRight+"\nbottom "+artboardBottom+"\nTheleft: "+horziontalCenterPosition+"\nThevert: "+verticalCenterPosition);

activeDoc.rulerOrigin = [horziontalCenterPosition,verticalCenterPosition];

app.selection = [];

activeDoc.selectObjectsOnActiveArtboard();

// app.executeMenuCommand ('selectallinartboard');

    // Check if anything is selected:

    if (selection.length > 0)

    {

        for (j = 0; j < selection.length; j++)

        {

            selection.resize (scale*100, scale*100, true, true, true, true, scale*100, Transformation.DOCUMENTORIGIN);

        }

    }

var scaledArtboardRect = newRect(-abProps.width/2  * scale, -abProps.height/2  * scale, abProps.width * scale,abProps.height * scale);

activeDoc.artboards.artboardRect = scaledArtboardRect;   

}

activeDoc.rulerOrigin = originalOrigin;

// Artboard bounds helper (used above):

function getArtboardBounds(artboard) {

  var bounds = artboard.artboardRect,

      left   = bounds[0],

      top    = bounds[1],

      right  = bounds[2],

      bottom = bounds[3],

      width  = right - left,

      height = top - bottom,

      props  = {

        left   : left,

        top    : top,

        width  : width,

        height : height

      };

  return props;

}

function findRequiredScale(props) {

    var scale = Math.min(requiredABsize / props.height, requiredABsize / props.width);

    if (scale >1)

    return scale;

    else

    return 1;

}

function newRect(x, y, width, height)

{

    var l = 0;

    var t = 1;

    var r = 2;

    var b = 3;

    var rect = [];

    rect = x;

    rect = -y;

    rect = width + x;

    rect = -(height - rect);

    return rect;

};

Likes

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