Skip to main content
Known Participant
September 9, 2022
Answered

Action that converts artboard to specific size [Letter Size]

  • September 9, 2022
  • 4 replies
  • 758 views

I have a different size of artboard, I want to record an action to convert the artboard to letter size.



This topic has been closed for replies.
Correct answer Kernzy

Not the cleanest code, but it's operational...

var docRef = app.activeDocument;
var docRef = app.activeDocument;
var ABs = docRef.artboards;
var choice;
//Creates new Popup
var Pallette = new Window ("dialog", "Artboard Resizer");
Pallette.add ("statictext", undefined, "Pick a size");
Pallette.orientation = "row";
//Dropdown Menu
var myDropdown = Pallette.add ("dropdownlist", undefined, [
"8.5\" x 11\"",
"11\" x 8.5\"",
"12\" x 12\"",
"12\" x 16\"",
"16\" x 12\"",
"24\" x 12\"",
"32\" x 20\""
]);
myDropdown.selection = 0
var group3 = Pallette.add("group");
    group3.orientation = "row";
    //var a = group3.add("radiobutton", undefined, "Single Artboard");
    var a = group3.add("radiobutton", undefined, "All Artboards");
    var radiobuttons = [a];
    a.checkedState = false;
    for (var i = 0; i < radiobuttons.length; i++) {
    (function (i) {
        radiobuttons[i].onClick = function () {
            method = radiobuttons[i].text;
        };
    })(i);
 }

    var myButtonGroup =  Pallette.add ("group");
    myButtonGroup.orientation = "column";
    var btnCreate = myButtonGroup.add ("button", undefined, "OK");
    btnCreate.onClick = function () {
    choice = myDropdown.selection.text;
    method = radiobuttons[i].text;
    w.button.onClick = function () {

        w.close();
   
    }  
 };
Pallette.show ();

var method = method;

if(method == "All Artboards"){

    if (choice == "8.5\" x 11\"") {
        resizeAllArtboards(8.5 * 72, 11 * 72);
    } else if (choice == "11\" x 8.5\"") {
        resizeAllArtboards(11 * 72, 8.5 * 72);
    } else if (choice == "12\" x 12\"") {
        resizeAllArtboards(12 * 72, 12 * 72);
    } else if (choice == "12\" x 16\"") {
        resizeAllArtboards(12 * 72, 16 * 72);
    } else if (choice == "16\" x 12\"") {
        resizeAllArtboards(16 * 72, 12 * 72);
    } else if (choice == "24\" x 12\"") {
        resizeAllArtboards(24 * 72, 12 * 72);
    }  else if (choice == "32\" x 20\"") {
        resizeAllArtboards(32 * 72, 20 * 72);
    }}
else {
    // new code
    if (choice == "8.5\" x 11\"") {
        resizeArtboard(8.5 * 72, 11 * 72);
    } else if (choice == "11\" x 8.5\"") {
        resizeArtboard(11 * 72, 8.5 * 72);
    } else if (choice == "12\" x 12\"") {
        resizeArtboard(12 * 72, 12 * 72);
    } else if (choice == "12\" x 16\"") {
        resizeArtboard(12 * 72, 16 * 72);
    } else if (choice == "16\" x 12\"") {
        resizeArtboard(16 * 72, 12 * 72);
    } else if (choice == "24\" x 12\"") {
        resizeArtboard(24 * 72, 12 * 72);
    }  else if (choice == "32\" x 20\"") {
        resizeArtboard(32 * 72, 20 * 72);
    }
   
 }


function resizeAllArtboards(w, h) {
        for (var i = 0; i < ABs.length; i++) {
        app.selection = null;
        ABs.setActiveArtboardIndex(i);
        var idx  = docRef.artboards.getActiveArtboardIndex();
        var AB  = docRef.artboards[idx];
        var ABR = AB.artboardRect;
        var xC = ABR[0]+((ABR[2]-ABR[0])/2);
        var yC = ABR[1]+((ABR[3]-ABR[1])/2);
        AB.artboardRect = [xC-w/2, yC+h/2, xC+w/2, yC-h/2];
  }
 }

function resizeArtboard(w, h) {
    var idx  = docRef.artboards.getActiveArtboardIndex();
    var AB  = docRef.artboards[idx];
    var ABR = AB.artboardRect;
    var xC = ABR[0]+((ABR[2]-ABR[0])/2);
    var yC = ABR[1]+((ABR[3]-ABR[1])/2);
    AB.artboardRect = [xC-w/2, yC+h/2, xC+w/2, yC-h/2];
    }

 

4 replies

Kernzy
KernzyCorrect answer
Inspiring
September 9, 2022

Not the cleanest code, but it's operational...

var docRef = app.activeDocument;
var docRef = app.activeDocument;
var ABs = docRef.artboards;
var choice;
//Creates new Popup
var Pallette = new Window ("dialog", "Artboard Resizer");
Pallette.add ("statictext", undefined, "Pick a size");
Pallette.orientation = "row";
//Dropdown Menu
var myDropdown = Pallette.add ("dropdownlist", undefined, [
"8.5\" x 11\"",
"11\" x 8.5\"",
"12\" x 12\"",
"12\" x 16\"",
"16\" x 12\"",
"24\" x 12\"",
"32\" x 20\""
]);
myDropdown.selection = 0
var group3 = Pallette.add("group");
    group3.orientation = "row";
    //var a = group3.add("radiobutton", undefined, "Single Artboard");
    var a = group3.add("radiobutton", undefined, "All Artboards");
    var radiobuttons = [a];
    a.checkedState = false;
    for (var i = 0; i < radiobuttons.length; i++) {
    (function (i) {
        radiobuttons[i].onClick = function () {
            method = radiobuttons[i].text;
        };
    })(i);
 }

    var myButtonGroup =  Pallette.add ("group");
    myButtonGroup.orientation = "column";
    var btnCreate = myButtonGroup.add ("button", undefined, "OK");
    btnCreate.onClick = function () {
    choice = myDropdown.selection.text;
    method = radiobuttons[i].text;
    w.button.onClick = function () {

        w.close();
   
    }  
 };
Pallette.show ();

var method = method;

if(method == "All Artboards"){

    if (choice == "8.5\" x 11\"") {
        resizeAllArtboards(8.5 * 72, 11 * 72);
    } else if (choice == "11\" x 8.5\"") {
        resizeAllArtboards(11 * 72, 8.5 * 72);
    } else if (choice == "12\" x 12\"") {
        resizeAllArtboards(12 * 72, 12 * 72);
    } else if (choice == "12\" x 16\"") {
        resizeAllArtboards(12 * 72, 16 * 72);
    } else if (choice == "16\" x 12\"") {
        resizeAllArtboards(16 * 72, 12 * 72);
    } else if (choice == "24\" x 12\"") {
        resizeAllArtboards(24 * 72, 12 * 72);
    }  else if (choice == "32\" x 20\"") {
        resizeAllArtboards(32 * 72, 20 * 72);
    }}
else {
    // new code
    if (choice == "8.5\" x 11\"") {
        resizeArtboard(8.5 * 72, 11 * 72);
    } else if (choice == "11\" x 8.5\"") {
        resizeArtboard(11 * 72, 8.5 * 72);
    } else if (choice == "12\" x 12\"") {
        resizeArtboard(12 * 72, 12 * 72);
    } else if (choice == "12\" x 16\"") {
        resizeArtboard(12 * 72, 16 * 72);
    } else if (choice == "16\" x 12\"") {
        resizeArtboard(16 * 72, 12 * 72);
    } else if (choice == "24\" x 12\"") {
        resizeArtboard(24 * 72, 12 * 72);
    }  else if (choice == "32\" x 20\"") {
        resizeArtboard(32 * 72, 20 * 72);
    }
   
 }


function resizeAllArtboards(w, h) {
        for (var i = 0; i < ABs.length; i++) {
        app.selection = null;
        ABs.setActiveArtboardIndex(i);
        var idx  = docRef.artboards.getActiveArtboardIndex();
        var AB  = docRef.artboards[idx];
        var ABR = AB.artboardRect;
        var xC = ABR[0]+((ABR[2]-ABR[0])/2);
        var yC = ABR[1]+((ABR[3]-ABR[1])/2);
        AB.artboardRect = [xC-w/2, yC+h/2, xC+w/2, yC-h/2];
  }
 }

function resizeArtboard(w, h) {
    var idx  = docRef.artboards.getActiveArtboardIndex();
    var AB  = docRef.artboards[idx];
    var ABR = AB.artboardRect;
    var xC = ABR[0]+((ABR[2]-ABR[0])/2);
    var yC = ABR[1]+((ABR[3]-ABR[1])/2);
    AB.artboardRect = [xC-w/2, yC+h/2, xC+w/2, yC-h/2];
    }

 

Known Participant
September 15, 2022

Thank you for the effort. Appreciated

Kurt Gold
Community Expert
Community Expert
September 9, 2022

Could easily be done with an action.

 

Record:

 

- Create rectangle (letter size)
- H/V align rectangle to artboard.
- Object menu > Artboards > Fit to Selected Art.
- Delete rectangle.

 

Known Participant
September 15, 2022

This method worked.

Thank you!

femkeblanco
Legend
September 9, 2022

Could easily be done with a script.  

Known Participant
September 15, 2022

This is noted. Thank you

Mylenium
Legend
September 9, 2022

As I was educated the other day artboards are not "axction-able", so there's no way to do that. You have to do it manually.

 

Mylenium

Known Participant
September 15, 2022

Thank you for your response. Appreciated