9 Replies Latest reply on Dec 14, 2016 9:51 AM by StrongBeaver

    Adding Artboards ?

    StrongBeaver Level 3

      How do you add and name an ArtBoard ? I've been putting Artboards.add() in a variable but keep getting an error ?

        • 1. Re: Adding Artboards ?
          o-marat Level 3

          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';
          • 2. Re: Adding Artboards ?
            Ten A Adobe Community Professional

            The add method under the Artboards needs argument like below code:

            app.activeDocument.artboards.add([400,0,683,-419]).name = "testArtboard1";
            1 person found this helpful
            • 3. Re: Adding Artboards ?
              StrongBeaver Level 3

              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 ?

              • 4. Re: Adding Artboards ?
                williamadowling Level 4

                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)

                • 5. Re: Adding Artboards ?
                  Silly-V Adobe Community Professional

                  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.

                  • 6. Re: Adding Artboards ?
                    williamadowling Level 4

                    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.

                    • 7. Re: Adding Artboards ?
                      StrongBeaver Level 3

                      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 ?

                      • 8. Re: Adding Artboards ?
                        Silly-V Adobe Community Professional

                        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]);

                        1 person found this helpful
                        • 9. Re: Adding Artboards ?
                          StrongBeaver Level 3

                          Thanks for the tip