Copy link to clipboard
Copied
How do you add and name an ArtBoard ? I've been putting Artboards.add() in a variable but keep getting an error ?
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]);
Copy link to clipboard
Copied
Hi, StrongBeaver !
Create a new or select an existing rectangle, than run this script:
var selRect = selection[0].geometricBounds;
var ab = activeDocument.artboards.add(selRect);
ab.name = 'test_ab';
Copy link to clipboard
Copied
The add method under the Artboards needs argument like below code:
app.activeDocument.artboards.add([400,0,683,-419]).name = "testArtboard1";
Copy link to clipboard
Copied
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 ?
Copy link to clipboard
Copied
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.
artboards.add(left,top,right,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)
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
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 ?
Copy link to clipboard
Copied
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]);
Copy link to clipboard
Copied
Thanks for the tip