Javascript Question

How to create Rectangle object required by add method of the artboards object in Illustrator CS5.1+?

I'm trying to add new artboard with the help of java script. I wasn't able to find solution nowhere. The scripting guidelines from adobe are just poor (to not use more strong words).

What ever I'm trying it returns the error:

Error 1242: Illegal argument - argument 1 - Rectangle value expected

when I use value of
from other artboard then it creates artboard in the same place but I can't modify it (resize) which makes this option useless.

artboards.add([0,0,200,50]);//Error 1200: an Illustrator error coccurred: 1346458189('PARAM')
var rect = artboards[0].artboardRect;
rect[0] = 0;
rect[1] = 0;
rect[2] = 200;
rect[3] = 50;
artboards.add(rect);//Error 1242: Illegal argument - argument 1 - Rectangle value expected

Answer Source

After searching extensively I've found this workaround:

var newRect = function(x, y, width, height) {
    var l = 0;
    var t = 1;
    var r = 2;
    var b = 3;

    var rect = [];

    rect[l] = x;
    rect[t] = -y;
    rect[r] = width + x;
    rect[b] = -(height - rect[t]);

    return rect;

artboard = artboards.add(artboards[0].artboardRect); = "new name";
artboard.artboardRect = newRect(0, 0, 200, 50);
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download