1 2 Previous Next 49 Replies Latest reply: Oct 28, 2014 9:44 AM by ThinkingThings RSS

    Resize Artboard

    Community Member
      Unsure if Im asking in the right spot but is it possible to automate the resizing of the artboard say from A0 down to A1
        • 1. Re: Resize Artboard
          Larry G. Schneider MVP
          No. Artboard size is created with the document and cannot be changed.

          From the Scripting Reference:

          A documents color space, height, and width can only be set when the document is created. You cannot modify these properties in an existing document.

          You would have to create a new document at the right size and move everything to the new document.
          • 2. Re: Resize Artboard
            Community Member
            Dang

            Thanx for the very quick response.

            Ok can I ask this then
            What I really want to do is automate the making of PDF's of multiple standard sizes, outline text 71% reduction each time so that I get A0 down to A4 final PDF's is this possible in some way
            • 3. Re: Resize Artboard
              Community Member

              The only way I have found to do this is to copy the contents of the original into a new document.

              Here is my code:

               

               

              tell application "Adobe Illustrator"

               

              activate

              open your_doc.ai --replace with your filename and path

              tell me to do shell script "sleep 3"

               

              tell application "System Events" --Select all.

              tell application "Adobe Illustrator" to activate

              key code 0 using command down

              end tell

               

               

              tell application "System Events" --Group objects, may not be necessary.

              tell application "Adobe Illustrator" to activate

              key code 5 using command down

              end tell

               

               

              tell application "System Events" --Copy selection.

              tell application "Adobe Illustrator" to activate

              key code 8 using command down

              end tell

               

              close this_file without saving --out with the old, in with the new

               

               

              --make a new artboard with the appropriate dimentions

              set docRef to make new document with properties class caCS»:«constant eCLSeCyM», «class pSHw»:205.2, «class pSHh»:61.2, «class pNAr»:1, «class pALy»:«constant eDALpGrR», «class pASp»:20.0, «class pARC»:3}

               

              tell application "System Events"

              tell application "Adobe Illustrator" to activate

              key code 9 using command down

              end tell

               

               

               

              end tell

               

               

              ------------------

               

              In the above, "«class pSHw»:" is width in pixels, "«class pSHw»:" is height in pixels, «class pNAr»: is the number of artboards.

              The artboard with automatically be centered.

               

              I figured this out from messing with the default scripts.

               

              There is no way to do it in the current document, so this is the only workaround.

               

              Cheers.

              • 4. Re: Resize Artboard
                azgolfer Community Member

                Not sure if this is what you want, but you can resize the artboard in CS4 with this call in javascript

                 

                app.activeDocument.artboards[0].artboardRect = [333,1182,1197,318];

                • 5. Re: Resize Artboard
                  CaptainJoey Community Member

                  I get a crash in VB when I try it in CS4 VB script.

                   

                  aiDoc.ArtBoard.ArtboardRect(0)=333
                  aiDoc.ArtBoard.ArtboardRect(1)=1182
                  aiDoc.ArtBoard.ArtboardRect(2)=1197
                  aiDoc.ArtBoard.ArtboardRect(3)=318

                   


                  • 6. Re: Resize Artboard
                    panda42_s

                    I use Applescript, so I do not know if this works for anybody else, but this is where I ended up:

                     

                    tell application "Adobe Illustrator"

                    tell current document

                    tell artboard 1

                     

                    --get original page size

                    set artPage to artboard rectangle

                    set x1orig to item 1 of artPage

                    set y1orig to item 2 of artPage

                    set x2orig to item 3 of artPage

                    set y2orig to item 4 of artPage

                     

                    --determine new page size (add half inch in each direction)

                    set x1new to (x1orig - 36) as real

                    set y1new to (y1orig + 36) as real

                    set x2new to (x2orig + 36) as real

                    set y2new to (y2orig - 36) as real

                     

                    --set new page size

                    set artboard rectangle to {x1new, y1new, x2new, y2new}

                     

                    end tell --artboard

                    end tell --document

                    end tell --AI

                    • 7. Re: Resize Artboard
                      D Zurn Community Member

                      I wrote a Javascript that will resize the artboard in Illustrator CS4.

                       

                       
                      /**********************************************************
                       
                      FitArtboardToArt.jsx
                      
                      DESCRIPTION
                      In Adobe Illustrator CS4, fit the artboard to the visible bounds of a document.
                      NOTE: The script leaves behind some artifacts in the document window but is correct.
                      
                      Darryl Zurn, 2009-11-25 daz-scripting@zzzurn.com
                       
                      **********************************************************/
                      
                      if (app.documents.length > 0) {
                           var docRef = app.activeDocument;
                           if (docRef.artboards.length > 1) 
                           {
                                alert('Need exactly one artboard');
                                quit;
                                }
                           // Found 1 artboard
                           
                           var myVisibleBounds = docRef.pageItems[0].visibleBounds;
                           
                           // The VisibleBounds rect is in this order: left, right, top, bottom
                           // so use variables to show which side we are using
                           var myLeft = 0;   var myRight = 1;   var myTop = 2;   var myBottom = 3; 
                           for ( var i = 1; i < docRef.pageItems.length ; i += 1 ) 
                           { 
                                // We want the ultimate maximum bounds, so select the minimum left and bottom, and max right and top of our rect.
                                myVisibleBounds[myLeft  ] = Math.min( myVisibleBounds[myLeft  ], docRef.pageItems[i].visibleBounds[myLeft  ] );
                                myVisibleBounds[myRight ] = Math.max( myVisibleBounds[myRight ], docRef.pageItems[i].visibleBounds[myRight ] );
                                myVisibleBounds[myTop   ] = Math.max( myVisibleBounds[myTop   ], docRef.pageItems[i].visibleBounds[myTop   ] );
                                myVisibleBounds[myBottom] = Math.min( myVisibleBounds[myBottom], docRef.pageItems[i].visibleBounds[myBottom] );
                                }
                           // We have our maximum bounds, so use it to set the document's (only) artboard
                           docRef.artboards[0].artboardRect = myVisibleBounds;
                      }
                      else {
                           alert('Open a document before running this script', 'Error running FitArtboardToArt.jsx');
                      }
                      
                      • 8. Re: Resize Artboard
                        qdesign8 Community Member

                        I amended panda42_s script to allow variable adjustment of height and width:

                         

                         

                        tell application "Adobe Illustrator"

                        tell current document

                        tell artboard 1

                         

                        --get original page size

                        set artPage to artboard rectangle

                        set x1orig to item 1 of artPage

                        set y1orig to item 2 of artPage

                        set x2orig to item 3 of artPage

                        set y2orig to item 4 of artPage

                         

                         

                        set newHeight to text returned of (display dialog "enter increase in height in mm" default answer "")

                         

                        set newWidth to text returned of (display dialog "enter increase in width in mm" default answer "")

                         

                         

                        --determine new page size (add half inch in each direction)

                        set x1new to (x1orig - newWidth / 2 * 2.834645) as real

                        set y1new to (y1orig + newHeight / 2 * 2.834645) as real

                        set x2new to (x2orig + newWidth / 2 * 2.834645) as real

                        set y2new to (y2orig - newHeight / 2 * 2.834645) as real

                         

                        --set new page size

                        set artboard rectangle to {x1new, y1new, x2new, y2new}

                         

                        end tell --artboard

                        end tell --document

                        end tell --AI

                        • 9. Re: Resize Artboard
                          qdesign8 Community Member

                          Sorry forgot to take comment out of previous post (not that it stops it from working):

                           

                          tell application "Adobe Illustrator"

                          tell current document

                          tell artboard 1

                           

                          --get original page size

                          set artPage to artboard rectangle

                          set x1orig to item 1 of artPage

                          set y1orig to item 2 of artPage

                          set x2orig to item 3 of artPage

                          set y2orig to item 4 of artPage

                           

                           

                          set newHeight to text returned of (display dialog "enter increase in height in mm" default answer "")

                           

                          set newWidth to text returned of (display dialog "enter increase in width in mm" default answer "")

                           

                           

                          --determine new page size

                          set x1new to (x1orig - newWidth / 2 * 2.834645) as real

                          set y1new to (y1orig + newHeight / 2 * 2.834645) as real

                          set x2new to (x2orig + newWidth / 2 * 2.834645) as real

                          set y2new to (y2orig - newHeight / 2 * 2.834645) as real

                           

                          --set new page size

                          set artboard rectangle to {x1new, y1new, x2new, y2new}

                           

                          end tell --artboard

                          end tell --document

                          end tell --AI

                          • 10. Re: Resize Artboard
                            hari_kdr Community Member

                            Hi D Zurn

                             

                            Your script is really working great. Is it possible that we can maintain some certain distance instead of fitting exactly? I mean now it is exactly fitting with artwork. I am requesting to maintain 10mm from 4 sides. 

                             

                            If it is possible, please edit this script.

                             

                             

                            if (app.documents.length > 0) {
                                 var docRef = app.activeDocument;
                                 if (docRef.artboards.length > 1)
                                 {
                                      alert('Need exactly one artboard');
                                      quit;
                                      }
                                 // Found 1 artboard
                                
                                 var myVisibleBounds = docRef.pageItems[0].visibleBounds;
                                
                                 // The VisibleBounds rect is in this order: left, right, top, bottom
                                 // so use variables to show which side we are using
                                 var myLeft = 0;   var myRight = 1;   var myTop = 2;   var myBottom = 3;
                                 for ( var i = 1; i < docRef.pageItems.length ; i += 1 )
                                 {
                                      // We want the ultimate maximum bounds, so select the minimum left and bottom, and max right and top of our rect.
                                      myVisibleBounds[myLeft  ] = Math.min( myVisibleBounds[myLeft  ], docRef.pageItems[i].visibleBounds[myLeft  ] );
                                      myVisibleBounds[myRight ] = Math.max( myVisibleBounds[myRight ], docRef.pageItems[i].visibleBounds[myRight ] );
                                      myVisibleBounds[myTop   ] = Math.max( myVisibleBounds[myTop   ], docRef.pageItems[i].visibleBounds[myTop   ] );
                                      myVisibleBounds[myBottom] = Math.min( myVisibleBounds[myBottom], docRef.pageItems[i].visibleBounds[myBottom] );
                                      }
                                 // We have our maximum bounds, so use it to set the document's (only) artboard
                                 docRef.artboards[0].artboardRect = myVisibleBounds;
                            }
                            else {
                                 alert('Open a document before running this script', 'Error running FitArtboardToArt.jsx');
                            }

                             

                            Thanks in advance..

                             

                            Regards

                            HARI

                            • 11. Re: Resize Artboard
                              D Zurn Community Member

                              I got a message from another user who had modified my script to ask the user how much to add, and then did it. I thought it had been sent to the rest of the group too, but I don't see it and I think I deleted the message.

                               

                              I'll try my other computer to see if the script is still around, or hopefully they can repost it to the forum.

                               

                              Darryl

                              • 12. Re: Resize Artboard
                                hari_kdr Community Member

                                Hi D Zurn

                                 

                                Thanks for your reply,

                                 

                                Could you guys please post the updated script.

                                 

                                Thanks in advance.

                                 

                                Regards

                                HARI

                                • 13. Re: Resize Artboard
                                  Tom Friedmann Community Member

                                  Hi,

                                   

                                  First an elegant solution, and then a question.

                                   

                                  If your goal is to reduce the size of the artboard to the visible boundaries of the artwork, this works like gang busters.  (I can't take credit, but I can share it.)

                                   

                                  #target illustrator

                                   

                                  var doc = app.activeDocument;
                                  doc.artboards[0].artboardRect = doc.visibleBounds;

                                   

                                   

                                  Now, I'd like to enlarge the artboard on all sides by say, 20px.  I don't want to set specific X and Y coordinates, since the art I will be running it on is variably-sized.

                                  How do we then enlarge the artboard dimensions relatively from the new artboard values? Thanks for the Applescript, Panda, btw.

                                   

                                   

                                  This should be easy, but I can't quite figure it out. Any help is much appreciated.

                                   

                                  Thanks in advance, you'll be saving my rear end.

                                   

                                  -t

                                  • 14. Re: Resize Artboard
                                    Tom Friedmann Community Member

                                    OK, with some help, I have a JS ExtendScript that works, but I still need help making it more batchable.

                                     

                                    This script below will for perform the following two changes to all open documents:

                                     

                                    1. Shrink the artboard to the "visible" art (beware of clipping masks, which it sometimes breaks on)
                                    2. Increases the artboard out 20 increments on all sides.  Keep in mind that the values are in the sequence are: left, top, right, and bottom dimensions.  It's helpful to know that the left value and the bottom value begin at zero; thus, when you want to add space to the artboard, you need negative numbers, as shown.
                                    3. Save and close the open documents.

                                     

                                     

                                    var myDocs = app.documents;
                                    var i = 0;

                                     

                                    for (i = myDocs.length-1 ; i >= 0; i--)

                                     

                                    {

                                     

                                        var doc = myDocs[i];

                                     

                                        app.activeDocument= doc;

                                     

                                        var myVisibleBounds = doc.visibleBounds; //Rect, which is an array;

                                     

                                        myVisibleBounds[0] -= 20;

                                     

                                        myVisibleBounds[1] += 20;

                                     

                                        myVisibleBounds[2] += 20;

                                     

                                        myVisibleBounds[3] -= 20;

                                     

                                        doc.artboards[0].artboardRect = myVisibleBounds;

                                     

                                        doc.close(SaveOptions.SAVECHANGES);

                                     

                                    }

                                     

                                     

                                    But this is limited, since you can only load so many files at once into Illustrator.  Does anyone know how to point the JS at a folder?

                                     

                                    Thanks!

                                     

                                    Tom

                                    • 15. Re: Resize Artboard
                                      Muppet Mark-QAl63s Community Member

                                      Some thing like this should do it for CS5… Plus I did it so it's simple enough to adjust…

                                       

                                      #target illustrator
                                       
                                      var doc = app.activeDocument;
                                      
                                      var docVB = doc.visibleBounds;
                                      
                                      var left = docVB[0] - 20;
                                      var top = docVB[1] + 20;
                                      var right = docVB[2] + 20;
                                      var bottom = docVB[3] - 20;
                                      
                                      var ab = doc.artboards.getActiveArtboardIndex();
                                      
                                      doc.artboards[ab].artboardRect = [left,top,right,bottom];
                                      

                                      • 16. Re: Resize Artboard
                                        Tom Friedmann Community Member

                                        Muppet,

                                         

                                        Great, thanks for the code.  Any thoughts on how to make it more batchable?  I've got thousands of files to do...

                                         

                                        -Tom

                                        • 17. Re: Resize Artboard
                                          Muppet Mark-QAl63s Community Member

                                          Firstly… You could just save that snippet in to Illustrator's scripts folder, make a action that calls it via 'insert menu item' from the flyout, once you have the recorded and saved action use as a batch… The other way would be to have a purpose built script that does the whole of the processing for you… Much would depend up on the files in question where they are within your file system… If you need the latter then start a new topic this is an old thread… If you go down the action route don't forget that the script call will be forgotten by the app at quit… A much complained about issue…

                                          • 18. Re: Resize Artboard
                                            Tom Friedmann Community Member

                                             

                                            Great tip about "Insert Menu Item". Once I placed my script in the Illustrator CS4>Presets>en_US>Scripts folder it showed up in the menu list, and I could access it through batch.  I modified the script to be used in the batch, and I'll include that here:

                                             

                                             

                                                app.activeDocument= doc;
                                                var myVisibleBounds = doc.visibleBounds; //Rect, which is an array;
                                                myVisibleBounds[0] -= 20; //left coordinate (use negative values to add artboard)
                                                myVisibleBounds[1] += 20; //ltop coordinate
                                                myVisibleBounds[2] += 20; //right coordinate
                                                myVisibleBounds[3] -= 20; //bottom coordinate (use negative values to add artboard)
                                                doc.artboards[0].artboardRect = myVisibleBounds;

                                             

                                            Thanks for your help, Muppet!

                                             

                                            tf

                                            • 19. Re: Resize Artboard
                                              tomprager Community Member

                                              This script seems to be exactly what I'm looking for, also, but it's not working for me. I suspect my problem is that I'm in CS3. Can anyone dumb it down to work in CS3?

                                              • 20. Re: Resize Artboard
                                                Muppet Mark Community Member

                                                Sorry it's just not possible pre CS4…

                                                • 21. Re: Resize Artboard
                                                  garisimola Community Member

                                                  I realize this post is a bit dated, but was hoping someone might know how to modify this script; I have been using it daily, and have it saved three ways in my script folder (one reduces the artboard to the art, one adds 1/8" distance from the art, and one adds 5" distance). Is there a way to make the 'edge' a percentage of the artwork, so if the art was 10"x10" and the percentage was 10% it would add an inch, whereas art 100"x100" with 10% would get a 10" border? I wouldn't need to set the percentage each time; that could be built into the script.

                                                   

                                                  -g-

                                                  • 22. Re: Resize Artboard
                                                    ThinkingThings Community Member

                                                    OK -- this will challange you a little bit, in that you have to do a little conversion from VB.NET to JS, but this should do the trick for you. It should be easy enough. At minimum, you'll understand the differences a little bit.

                                                     

                                                    A few caveats:

                                                     

                                                    1) You may or may not find that you desire a consistent margin on a rectangular-dimensioned collection of pathitems. Since you chose a "square" excample, you may or may not have considered that.

                                                     

                                                    2) This has been tested on CS6. I beileve that it works back to CS5, but I forget when (what version) the vertical scale was changed so before that it probably needs some adjustment.

                                                     

                                                    3) I used the variable abMargin to allow you to adjust easily the percentage that you desire in margins for your artboard. Note: '10' = 10%. While I could have made the code a little cleaner with less variables, I thought that spelling it out may help you understand the logic better.

                                                     

                                                    4) I noticed in a previous post's example the use of Artboards(0). While the documentation states a zero-based array value, in my testing I could only get it work as a 1-base array. I'm sure that I am missing something that someone else may spell out.

                                                     

                                                    5) Lastly (thank goodness) in the future, you may be better served by opening a new discussion and referencing the old discussion link. That's just my opinion, though. No harm, no foul.

                                                     

                                                    So here you go. Hope this helps. Good luck!    -TT 

                                                     

                                                    ----------------

                                                     

                                                     

                                                    Public Sub DrawBorderPcnt(app As AI.Application, abMargin As Double)

                                                      Dim aDoc As AI.Document = app.ActiveDocument

                                                      Dim vb = aDoc.VisibleBounds

                                                      Dim width = (vb(2) - vb(0))  'left-right

                                                      Dim height = -(vb(3) - vb(1)) 'bottom-top

                                                      vb(0) -= (width * (1 + abMargin / 100) - width) / 2  'left

                                                      vb(1) += (height * (1 + abMargin / 100) - height) / 2 'top

                                                      vb(2) += (width * (1 + abMargin / 100) - width) / 2  'right

                                                      vb(3) -= (height * (1 + abMargin / 100) - height) / 2 'bottom

                                                      aDoc.Artboards(1).ArtboardRect = vb

                                                    End Sub

                                                     

                                                    ---------------

                                                     

                                                    PS: If you still need help in the conversion, let us know and if someone doesn't get to it first, I'll try to help. -TT

                                                    • 23. Re: Resize Artboard
                                                      garisimola Community Member

                                                       

                                                       

                                                      Thanks, TT for the reply -- the extent of my script abilities are making slight modifications to existing ones, so much of what you posted is beyond me. I think what you are doing is getting the width of the artboard, dividing by 100, adding 1, dividing this in half, and adding this number to each dimension. I'm not sure how abMargin works here... See if what I have below might work: 

                                                       

                                                      replace in the JS example:

                                                      var left = docVB[0] - 20;

                                                      var top = docVB[1] + 20;

                                                      var right = docVB[2] + 20;

                                                      var bottom = docVB[3] - 20;

                                                       

                                                      var left = docVB[0] - ((1+(docVB[0]-docVB[2])/100)/2)

                                                      etc...

                                                       

                                                      Thanks for any insights...

                                                       

                                                      -g-

                                                      • 24. Re: Resize Artboard
                                                        ThinkingThings Community Member

                                                        Garisimola,

                                                         

                                                        You're almost on the right track. I applaud your persistence. Work with me here and you will understand it a lot more in no time and you'll be coding this stuff in your sleep. Here's a little background of my thinking and the process as I coded it:

                                                         

                                                        Just a little background…

                                                        'abMargin' is a variable that I created to allow modularity to the function. So let's say the you wanted 10% margin, then abMargin would equal 10. That value is set by the "caller" (the process that would be calling this subroutine). To help you understand it better, you could replace 'abMargin' with '10' (as per your original request) and then you would have a 10% extended margin. By adding the variable, I just allowed the subroutine to allow a calling program to set the value (in percentage terms) of the margin. Admittedly, you didn’t ask for it so I am sorry if it confused you.

                                                         

                                                        Now to the logic…

                                                        Yes – we get the width of the artboard. I'll try to breakdown the math. I haven't had to do this in a LONG time so sorry if it's a little sloppy…

                                                        Let's let width = 20 (as in 20")

                                                        =(width * (1 + abMargin / 100) – width) / 2 'left point of new artboard

                                                        =(width * (1 + 10 / 100) – width) / 2

                                                        =(width * (1 * .1) – width) / 2

                                                        =(width * 1.1 – width) / 2

                                                        =(22 – width) / 2

                                                        =(2)/2

                                                        =1        <-- This if half of the additional margin area that will be added to the original design size. This will be added to each side or to the top and bottom of the document's VisibleBounds. Now remember that the values (width) are in Adobe points (72/inch). So to the script 1 actually equals 72, while the original width would be 1440…. Just FYI. Like I said in my original reply post, I could have slimmed down the code to a little more efficient, but I thought that by doing it this way it might help you understand better.

                                                         

                                                        Now we do the same with the height. This is where caveat #1 comes in – not sure if you overlooked the need to clarify that you wanted 10% on each dimension (width and height) which is what this example that I provided does. If you wanted a consistent margin, then you need to specify which axis you prefer to use the 10% "of". That, of course, will change the script.

                                                         

                                                        So forget the -20 and +20 for the moment… those numbers are just points that you would have subtracted or added to the existing docVB (documentVisibleBounds) variable to get an artboard reference points for the OLD example.

                                                         

                                                        Consider this:

                                                         

                                                        My vb(x) (vb stands for VisibleBounds) is the equivalent to your JS docVB[x] where 'x' is 0-3.

                                                        vb(0) =left, vb(1)=top, vb(2)=right, vb(3)=bottom. See my example comments.

                                                        Also note that going left to right on the width the numbers increase so to get the width in points you take vb(2)-vb(0). Vertically, in CS5+ (I think) you start at 0 and go negative.

                                                         

                                                        So here's a start for you’re the left side of your new artboard. '1.1' has been hard-coded in place of '1+abMargin/100'.

                                                         

                                                        var left = docVB[0] – ((docVB[2] - docVB[0])*1.1 - (docVB[2] - docVB[0]) / 2)

                                                         

                                                        Let us know is this helps you.

                                                         

                                                        -TT

                                                         

                                                        PS: I always liked this verse… "Give a man a fish and you feed him for a day. Teach a man to fish and you feed him for a lifetime." Many (including many here) have spent time and taught me. I'm happy to return the favor.

                                                        • 25. Re: Resize Artboard
                                                          garisimola Community Member

                                                          I have no idea what prompted you to help the hell out of me. I'm certainly not living right! I do, however, have a better handle on the script, and, of course, some questions. You gave me this:

                                                           

                                                            var left = docVB[0] – ((docVB[2] - docVB[0])*1.1 - (docVB[2] - docVB[0]) / 2)

                                                           

                                                          here, we set the left coordinate = left - ((right - left)*1.1 - (left - right)/2)

                                                           

                                                          this takes the distance (right - left), multiplies it by 10% (1.1) and then subtracts the distance (right - left)/2 leaving the amount we want to move from the left to more left (this number will be negative, yes?)

                                                           

                                                          q: why do I need to include the right - left -- can I just do this:

                                                           

                                                            left coordinate - left - ((right)*1.1 - (right)/2

                                                           

                                                          or is the coordinate for the right sometimes not = zero?

                                                           

                                                          extrapolating your work, this is what I get for the left, right, top, and bottom calculations:

                                                           

                                                          var left = docVB[0] – ((docVB[2] - docVB[0])*1.1 - (docVB[2] - docVB[0]) / 2)

                                                          var right = docVB[2] + ((docVB[2] - docVB[0])*1.1 - (docVB[2] - docVB[0]) / 2)

                                                          var top = docVB[1] + ((docVB[1] - docVB[3])*1.1 - (docVB[1] - docVB[3]) / 2)

                                                          var bottom = docVB[3] - ((docVB[1] - docVB[3])*1.1 - (docVB[1] - docVB[3]) / 2)

                                                           

                                                          This (hopefully) gives me a 10% increase in each direction. I finally understand your caveat regarding the margins now; if I have a 10" (w) x 2" (h) object the margins on the left-right would be .5" (total of 1"), but the top-bottom would only be .1" (total of .2") -- visually lopsided. I'd need to figure out in the function what was the longer dimension, determine 10% of that, and add 1/2 of that to all sides to get a consistent margin.

                                                           

                                                          Thanks for working through this with me.

                                                           

                                                          -g-

                                                          • 26. Re: Resize Artboard
                                                            ThinkingThings Community Member

                                                            garisimola wrote:

                                                             

                                                            I have no idea what prompted you to help the hell out of me.

                                                            I'm not sure either, but it is certainly enjoyable and rewarding to see progress. Keep it going.

                                                            this takes the distance (right - left), multiplies it by 10% (1.1) and then subtracts the distance (right - left)/2 leaving the amount we want to move from the left to more left (this number will be negative, yes?)

                                                            Well - it will be a number LESS than the original design left VB (VisibleBound). Possibly negative, possibly not. Depends on where your existing left VB is relative to your existing artboard. Usually artboard left is zero (although than can be changed), but remember that your VBs are of your design.

                                                            or is the coordinate for the right sometimes not = zero?

                                                            That is correct, for reasons explained above.

                                                            extrapolating your work, this is what I get for the left, right, top, and bottom calculations:

                                                             

                                                            var left = docVB[0] – ((docVB[2] - docVB[0])*1.1 - (docVB[2] - docVB[0]) / 2)

                                                            var right = docVB[2] + ((docVB[2] - docVB[0])*1.1 - (docVB[2] - docVB[0]) / 2)

                                                            var top = docVB[1] + ((docVB[1] - docVB[3])*1.1 - (docVB[1] - docVB[3]) / 2)

                                                            var bottom = docVB[3] - ((docVB[1] - docVB[3])*1.1 - (docVB[1] - docVB[3]) / 2)

                                                             

                                                            I think that you've got it.

                                                             

                                                            But now-- based on your new requirements (% of LONGER dimension +1/2") we're going to change a few things up, keeping you on your toes. I hope that it will make it easier and not more confusing. Here's the new VB.NET code:

                                                             

                                                            Public Sub AdjustArtboardSize(app As AI.Application, abMargin As Double)

                                                              Dim aDoc As AI.Document = app.ActiveDocument

                                                              Dim vb = aDoc.VisibleBounds

                                                              Dim width = (vb(2) - vb(0))     'left-right

                                                              Dim height = -(vb(3) - vb(1))    'bottom-top

                                                              Dim margin = Math.Max(width, height) * (abMargin / 100) / 2 + 36      '36pts = .5"

                                                              vb(0) -= margin    'left

                                                              vb(1) += margin    'top

                                                              vb(2) += margin    'right

                                                              vb(3) -= margin 'bottom

                                                              aDoc.Artboards(1).ArtboardRect = vb

                                                            End Sub

                                                             

                                                            A few notes: I've introduced a new 'margin' variable. I've taken the '1+' out of the equation, and now divide abMargin (or your desired % margin) by 100 to come up with, for example: abMargin = 10... so 10/100=.1 (you can hardcode that it you would like or create a new JS variable for the abMargin equivalent -- like: var abMargin = 10; ) and then divide that by 2 (which basically takes your 10% and applies 5% on each side). I add 36 (remember 1" = 72 Adobe points) - so that's your 1/2". 'Math.Max(width, height)' returns the greater of the two elements, thus giving you what you need for your "longer of the two) dimensions requirement. Multiply that result by the percentage calcs mentioned above and you have the consistent margin desired for each side. WIth all that said, the rest is really easy, as you just add or subtract the new "margin" from the existing VisibleBounds.

                                                             

                                                            So now we will be anxiously waiting your next post signalling SUCCESS! Or... we'll be happy to help you again if need be.

                                                             

                                                            Good luck!

                                                             

                                                            -TT

                                                             

                                                            PS: Sometimes I get on a roll and type away and then, realizing the time spent, I get lazy (or my ADD kicks in ) and don't always proofread before I post. Please forgive any typos or if something doesn't make sense. Hopefully it all does.

                                                            • 27. Re: Resize Artboard
                                                              ThinkingThings Community Member

                                                              I just reread your original post for some reason. I noticed that you talked about a 10% border. For some reason I had in my mind to split  that 10% to something like 5% on each side. Easy enough fix, though -- just remove the ' / 2 '.

                                                               

                                                              -TT

                                                              • 28. Re: Resize Artboard
                                                                garisimola Community Member

                                                                Well, I'm stuck -- I can't get the modified script to work -- when I put this in the script:

                                                                 

                                                                  var left = docVB[0] – ((docVB[2] - docVB[0])*1.1 - (docVB[2] - docVB[0]) / 2)

                                                                  var right = docVB[2] + ((docVB[2] - docVB[0])*1.1 - (docVB[2] - docVB[0]) / 2)

                                                                  var top = docVB[1] + ((docVB[1] - docVB[3])*1.1 - (docVB[1] - docVB[3]) / 2)

                                                                  var bottom = docVB[3] - ((docVB[1] - docVB[3])*1.1 - (docVB[1] - docVB[3]) / 2)

                                                                 

                                                                I get an error when running -- Error 8: Syntax error. Line: 7 (that's the first of the modified lines). Can you see the error?

                                                                 

                                                                Thanks!

                                                                 

                                                                -g-

                                                                • 29. Re: Resize Artboard
                                                                  ThinkingThings Community Member

                                                                  can you post your whole script or PM me with it? I'm not the JS guru, but I will do what I can...

                                                                  • 30. Re: Resize Artboard
                                                                    Gustavo Del Vechio Community Member

                                                                    This was already mentioned earlier by Larry, so just saying again:

                                                                     

                                                                    Once artboard is created, you cannot change it´s size. You define the size of an artboard when you create a new document.

                                                                     

                                                                    Gustavo.

                                                                    • 31. Re: Resize Artboard
                                                                      garisimola Community Member

                                                                      #target illustrator

                                                                       

                                                                      var doc = app.activeDocument;

                                                                       

                                                                      var docVB = doc.visibleBounds;

                                                                       

                                                                      var left = docVB[0] – (((docVB[2] - docVB[0])*1.1 - (docVB[2] - docVB[0])) / 2);

                                                                      var top = docVB[1] + (((docVB[1] - docVB[3])*1.1 - (docVB[1] - docVB[3])) / 2);

                                                                      var right = docVB[2] + (((docVB[2] - docVB[0])*1.1 - (docVB[2] - docVB[0])) / 2);

                                                                      var bottom = docVB[3] - (((docVB[1] - docVB[3])*1.1 - (docVB[1] - docVB[3])) / 2);

                                                                       

                                                                      var ab = doc.artboards.getActiveArtboardIndex();

                                                                       

                                                                      doc.artboards[ab].artboardRect = [left,top,right,bottom];

                                                                      • 32. Re: Resize Artboard
                                                                        garisimola Community Member

                                                                        Gustavo -- I use this script:

                                                                         

                                                                        --begin script--

                                                                         

                                                                        #target illustrator

                                                                         

                                                                        var doc = app.activeDocument;

                                                                         

                                                                        var docVB = doc.visibleBounds;

                                                                         

                                                                        var left = docVB[0] - 360;

                                                                        var top = docVB[1] + 360;

                                                                        var right = docVB[2] + 360;

                                                                        var bottom = docVB[3] - 360;

                                                                         

                                                                        var ab = doc.artboards.getActiveArtboardIndex();

                                                                         

                                                                        doc.artboards[ab].artboardRect = [left,top,right,bottom];

                                                                         

                                                                        --end script--

                                                                         

                                                                        and it resizes the artboard (it adds 5" on each side). Not sure what you mean about not being able to resize the artboard -- you certainly can do it manually, and this script will do it automatically. I'm just looking for a way to use a percentage of the art rather than a fixed measurement...

                                                                         

                                                                        -g-

                                                                        • 33. Re: Resize Artboard
                                                                          ThinkingThings Community Member

                                                                          @ Gustavo: that was the case in Pre-CS4, per Muppet Mark, but it is now changeable.

                                                                           

                                                                          @ garisimola: here's your script. Man, I just HATE Javascript! Lol!

                                                                           

                                                                          -----------------------

                                                                           

                                                                          AdjustArtboardSize(10, true);

                                                                          function AdjustArtboardSize(abMargin, useLongSideMargin) {
                                                                            var aDoc = activeDocument;
                                                                            var vb = new Array(aDoc.visibleBounds);
                                                                            vb = aDoc.visibleBounds;
                                                                            var width = (vb[2] - vb[0]);  // left-right
                                                                            var height = -(vb[3] - vb[1]);  // bottom-top
                                                                            if (useLongSideMargin == true)
                                                                              {
                                                                                var margin = Math.max(width, height) * (abMargin / 100) + 36; // 36pts = .5"
                                                                                vb[0] -= margin;    // left
                                                                                vb[1] += margin;   // top
                                                                                vb[2] += margin;   // right
                                                                                vb[3] -= margin;   // bottom
                                                                              }
                                                                            else
                                                                              {
                                                                                vb[0] -= (width * (1 + abMargin / 100) - width);  // left
                                                                                vb[1] += (height * (1 + abMargin / 100) - height); // top
                                                                                vb[2] += (width * (1 + abMargin / 100) - width);  // right
                                                                                vb[3] -= (height * (1 + abMargin / 100) - height); // bottom
                                                                              }
                                                                            aDoc.artboards[0].artboardRect = vb
                                                                          }

                                                                          • 34. Re: Resize Artboard
                                                                            garisimola Community Member

                                                                            Brilliant. A thousand thanks. I kind of get what is going on there, but it would have taken me a month of Sundays to get there (if ever). I'm guessing that the 10 in the first line corresponds to the percent increase, and I can change that if needed. One question: why do you need the if/else statement; does that have to do with determining the longest side?

                                                                             

                                                                            Do you have a charity (you can choose yourself) that could use a $25 donation? Seriously.

                                                                             

                                                                            Cheers!

                                                                             

                                                                            -g-

                                                                            • 35. Re: Resize Artboard
                                                                              CarlosCanto MVP

                                                                              Gustavo Del Vechio wrote:

                                                                               

                                                                              This was already mentioned earlier by Larry, so just saying again:

                                                                               

                                                                              Once artboard is created, you cannot change it´s size. You define the size of an artboard when you create a new document.

                                                                               

                                                                              Gustavo.

                                                                               

                                                                              Hi Gustavo, TT is correct, back in 2009 when this thread started, it wasn't possible, now we can change the Artboard size.

                                                                              • 36. Re: Resize Artboard
                                                                                ThinkingThings Community Member

                                                                                Garisimola,

                                                                                 

                                                                                The if/else statements are used if you set the second parameter in the calling statement to 'false'. When you first set out your requirements, it was indicated to just be a 10% margin. Being a packrat of code and always liking options, I kept the code intact for you and just gave you an option so that you can have it either way.   In VB.NET, just for giggles, I added this to my list of utilities that I will never remember where they are when I need them, but I'll have it just in case. This is what it looks like - where you just choose your margin percentage and check whether or not you want to use the long side margin consistently or not. Maybe some day when I'm famous this will be worth something, but don't hold your breath.

                                                                                0040.jpg

                                                                                 

                                                                                Regarding your offer of charitable kindness, you are quite a gentleman (or if I assume incorrectly, my profuse apologies, in which case I will say "gentleperson"). I heartily subscribe to the notion of paying it forward. As I said in a previous post, many here have helped me in the past and I'm simply returning the favor. This is truly one of the most generous sites in terms of folks helping other folks. If someone wants to learn, there are hundreds of people willing to help. That's what this site is all about. Sometimes (I admit) it bothers me when I see people asking for help when all they really want is free scripts customized to their needs, having no intention of even glancing at the code. You are NOT that way, and most are not. Still, I am always amazed that regulars are always willing to help. Pretty selfless, I think. Anyway (enough of me on my soap box) -- I am most honored at your offer, although I respectfully decline. Somewhere down the road, you'll get to return the good to someone else. That's pay enough for me.   If you still feel inclined to help someone monetarily (and it is entirely not necessary), pick one of YOUR favorite charities or something like a Make-A-Wish Foundation and maybe you can make one of some young child's limited days brighter and memorable thanks to you. If you choose to do that, please make yourself as the donor. We'll all feel good about it that way. Seriously.

                                                                                 

                                                                                Best of luck and please post again if you need some help. I'm glad that I could assist here.

                                                                                 

                                                                                Take care.

                                                                                 

                                                                                -TT

                                                                                • 37. Re: Resize Artboard
                                                                                  Gustavo Del Vechio Community Member

                                                                                  Hi Carlos and hi ThinkingThings

                                                                                   

                                                                                  Haha thank you very much for the correction. You are longer right!

                                                                                   

                                                                                  I got confused because I always try to create public scripts compatible with Illustrator CS3 and newer versions. So, I try to use as much methods and properties avaliable for CS3 as I can.

                                                                                   

                                                                                  But yes, with artboardRect you can change the size. Thank you for correcting me.

                                                                                   

                                                                                  Best Regards friends

                                                                                  Gustavo.

                                                                                  • 38. Re: Re: Resize Artboard
                                                                                    Kapil Devatwal Community Member
                                                                                    •   Dear All,

                                                                                     

                                                                                        I am so agree now to face bellow problem please assist please please.

                                                                                     

                                                                                    When i am set font size as 12 pt it will set prper font size for my pc but when i open this file to another pc then it will become a 11.89,14.0 etc why these please assist.inactiveforumnotifierIllustratorResize Artboard

                                                                                    • 39. Re: Resize Artboard
                                                                                      garisimola Community Member

                                                                                      Hope you are still out there, TT, and doing well -- I have another script question, and hope you might be able to help. It is based on the Resize Artboard script you modified. Is it possible to make that script behave in two manners: when nothing is selected do it's normal thing (artboard sized to 10% around art) but if an object or objects are selected then resize the Artboard to 10% around that object? I've gotten a little better with scripting (mostly hacking pre-existing JS scripts) but this has me stumped. Thanks, in advance, for any insight!

                                                                                       

                                                                                      Gary

                                                                                      1 2 Previous Next