1 person found this helpful
The add method under the Artboards needs argument like below code:
app.activeDocument.artboards.add([400,0,683,-419]).name = "testArtboard1";
Why the array of 4 values, I can't find in the docs what the last two values, in your example 683 & -419 are used for ?
the values are the bounds of the artboard relative to the coordinate system (either artboard or document).
the first value is left, the second is top, the third is right and the fourth is bottom.
It's tricky because that's the exact same syntax used for creating a rectangle, but rectangle uses different arguments:
var thePath = doc.pathItems.rectangle(x,y,width,height)
well, the pathItems.rectangle arguments are actually 'switched' (adding to fun confusion) and they accept the "top" (y) first and then the "left" second as arguments.
However when talking about the arrays returned from geometricBounds or visibleBounds, those arrays do come back as L - T - R - B, which is also the case for the artboardRect.
epic face palm. you are absolutely correct.
I'd edit my post if i could, but the hour has passed.
I often feel as though adobe built a team of 15-20 people to develop the illustrator API's. then they put each of those people into their own office with no phone or email capabilities and simply gave each person a task to do. And everybody did their task how they thought was best, rather than doing everything consistently. This is best evidenced by the atrocious list of "executeMenuCommand" arguments. Some arguments are all lowercase. some are camelCase, some are title case, some have spaces... what a mess!
I think that pathItems.rectangle() is something that i mess up every time and have to go back and fix because i'm so used to working with artboardRect and visibleBounds. blah.
William nice analogy of the API for Illustrator / Photoshop. As I begin my journey also scripting in Photoshop I came across someone who made a few plugins for Photoshop who shared the same frustrations as your analogy. Some API are wonderfully written, while others, not so much.
As for the bounds of the Artboard, atleast I know the values work counter clockwise. When attempting to enter in a positive value for the bound (visibleBound) for the bottom value of an Artboard, Illustrator fires back an error, I assume it must always be negative; any reason for this ?
1 person found this helpful
The bottom coordinate must absolutely be below the 'top' coordinate. Otherwise, the rectangle is inverted - similar how you drag a rectangle's bounding box all the way up over top of itself to get your rectangle reflected above its top bound.
So in order for me to make a new artboard with the bottom bound of 200, I have to make sure my 'top' coordinate for it is larger than 200 still.
doc.artboards.add([0, 400, 200, 200]);
Thanks for the tip