Skip navigation
Currently Being Moderated

Resize Artboard

Feb 5, 2009 5:22 PM

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
 
Replies
  • Currently Being Moderated
    Feb 5, 2009 5:31 PM   in reply to (RSW)
    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.
     
    |
    Mark as:
  • Currently Being Moderated
    Apr 20, 2009 9:16 AM   in reply to (RSW)

    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.

     
    |
    Mark as:
  • Currently Being Moderated
    Apr 20, 2009 10:35 AM   in reply to NoGODisGOOD

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

     
    |
    Mark as:
  • Currently Being Moderated
    Sep 1, 2009 4:54 PM   in reply to azgolfer

    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

     


     
    |
    Mark as:
  • Currently Being Moderated
    Oct 22, 2009 2:05 PM   in reply to (RSW)

    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

     
    |
    Mark as:
  • Currently Being Moderated
    Nov 25, 2009 11:06 AM   in reply to Larry G. Schneider

    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');
    }
    
     
    |
    Mark as:
  • Currently Being Moderated
    Oct 1, 2010 2:12 AM   in reply to (RSW)

    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

     
    |
    Mark as:
  • Currently Being Moderated
    Oct 1, 2010 2:15 AM   in reply to (RSW)

    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

     
    |
    Mark as:
  • Currently Being Moderated
    Oct 8, 2010 11:21 PM   in reply to D Zurn

    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

     
    |
    Mark as:
  • Currently Being Moderated
    Oct 9, 2010 4:29 AM   in reply to hari_kdr

    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

     
    |
    Mark as:
  • Currently Being Moderated
    Oct 9, 2010 4:57 AM   in reply to D Zurn

    Hi D Zurn

     

    Thanks for your reply,

     

    Could you guys please post the updated script.

     

    Thanks in advance.

     

    Regards

    HARI

     
    |
    Mark as:
  • Currently Being Moderated
    Apr 20, 2011 8:04 AM   in reply to (RSW)

    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

     
    |
    Mark as:
  • Currently Being Moderated
    Apr 20, 2011 12:28 PM   in reply to Tom Friedmann

    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

     
    |
    Mark as:
  • Currently Being Moderated
    Apr 20, 2011 11:51 AM   in reply to Tom Friedmann

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

     
    |
    Mark as:
  • Currently Being Moderated
    Apr 20, 2011 12:31 PM   in reply to Muppet Mark-QAl63s

    Muppet,

     

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

     

    -Tom

     
    |
    Mark as:
  • Currently Being Moderated
    Apr 20, 2011 1:11 PM   in reply to Tom Friedmann

    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…

     
    |
    Mark as:
  • Currently Being Moderated
    Apr 21, 2011 6:08 AM   in reply to Muppet Mark-QAl63s

    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

     
    |
    Mark as:
  • Currently Being Moderated
    Aug 19, 2011 1:09 PM   in reply to Tom Friedmann

    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?

     
    |
    Mark as:
  • Currently Being Moderated
    Aug 20, 2011 3:18 AM   in reply to tomprager

    Sorry it's just not possible pre CS4…

     
    |
    Mark as:

More Like This

  • Retrieving data ...

Bookmarked By (0)