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 artboard.artboardRect
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(artboards[0].artboardRect);//works
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
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 artboard.artboardRect
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(artboards[0].artboardRect);//works
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
Share
Improve this question
edited Dec 3, 2014 at 10:55
Raptor
54.2k47 gold badges246 silver badges399 bronze badges
asked Dec 3, 2014 at 9:50
Lukasz 'Severiaan' GrelaLukasz 'Severiaan' Grela
6,2587 gold badges45 silver badges83 bronze badges
3 Answers
Reset to default 10After 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);
artboard.name = "new name";
artboard.artboardRect = newRect(0, 0, 200, 50);
In several places in Illustrator Scripting PDFs rect
or someOtherPropRect
is defined as "array of 4 numbers". For example,
var document = app.documents.add();
$.writeln(document.artboards[0].artboardRect); // 0,792,612,0
returned values corresponds to topLeftX, topLeftY, bottomRightX, bottomRightY
.
To make sense of these values, we need to take a look at the coordiate system of Illustrator. Illustrator's UI uses a modified coordinate system, not the actual cartesian one. In other words, top left of the screen is the origin, not bottom left. But when scripting, actual cartesian coordinate system is used.
Because of this difference in coordinate system, entered values that are on the Y
axis should be nagative. So, if I want to reposition and resize the artboard, say, move it to (200,50)
and resize it to (400,300)
, what I need to do is:
var document = app.activeDocument;
var artboard = document.artboards[0];
var x = 200;
var y = 50;
var w = 400;
var h = 300;
artboard.artboardRect = [x, -y, (x + w), -(y + h)];
$.writeln(document.artboards[0].artboardRect); // 200, -50, 600, -350
This solution can be wrapped in a function:
function rect(x, y, w, h) {
return [x, -y, (x + w), -(y + h)];
}
artboard.artboardRect = rect(200, 50, 400, 300);
Both Y
and H
should be negative, otherwise you'll get an error saying
Error 1200: an Illustrator error occurred: 1346458189 ('PARM')
or incorrect reposition/resize.
Just in case someone else encounters Error: an Illustrator error occurred: 1346458189 ('PARM')
.
In CS6 at least this happens if height
is not negative or if width
is negative. This applies to all values of type rect
.
x
and y
can be positive or negative, it does't matter.
so this will work:
app.activeDocument.artboards.add([0 , 0, 200, -50]);
app.activeDocument.artboards.add([-10 , -10, 200, -50]);
app.activeDocument.artboards.add([10 , 10, 200, -50]);
but this will not work:
app.activeDocument.artboards.add([0 , 0, 200, 50])
app.activeDocument.artboards.add([0 , 0, -200, -50])
app.activeDocument.artboards.add([0 , 0, -200, 50])