• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
3

Script to Resize Artboard Dimensions if They're Below Specified Width or Height

Explorer ,
Sep 17, 2019 Sep 17, 2019

Copy link to clipboard

Copied

Hello world! I've built a script for Illustrator 2019 that checks if any artboards are under a certain minimum size specified as var width & var height and resizes any that are under those widths or heights to another specified height/width. It's commemted out so much that even a complete noob like me would understand every little thing it does.

 

It's based on this script here: https://github.com/iconifyit/ai-scripts/blob/master/Resize%20All%20Artboards.jsx

which i think is based on Carlos Cantos' script from these forums.

 

Here's a script for if you only need the width checked:

 

#target Illustrator  

    var idoc  = app.activeDocument;

    var width = (7*72) //# of inches multiplied by ppi which is 72
    //var height = (7*72) //uncomment this if you want to set height as well

    for (i=0; i<idoc.artboards.length; i++) {

            var abBounds = idoc.artboards[i].artboardRect; // the contents of this list are 0=left, 1=top, 2=right, 3=bottom


            var ableft = abBounds[0]; //these 4 vars just set the bounds of the artboard to readable names
            var abtop = abBounds[1];
            var abright = abBounds[2];
            var abbottom = abBounds[3];

            var abwidth = abBounds[2] - ableft; // these 2 vars calculate the width & height based on the bounds. right - left = width
            var abheight = abtop- abBounds[3]; // top - bottom = height

            var abctrx = abwidth/2+ableft; //these 2 vars help center the artboard
            //var abctry = abtop-abheight/2; //uncomment this if you want to set height as well

            var ableft = abctrx-width/2; //these 4 vars calculate the new bounds of the artboard
            //var abtop = abctry+height/2;  //uncomment this if you want to set height as well
            var abright = abctrx+width/2;
            //var abbottom = abctry-height/2;  //uncomment this if you want to set height as well


           /** if (abwidth < (6*72) && abheight < (6*72)) { //this if statement detects if your width & height is under your set # of inches multiplied by ppi which is 72 (since illustrator measures in pixels). if it's lower, it resizes it to var width & var height shown above.

                idoc.artboards[i].artboardRect = [ableft, abtop, abright, abbottom]; } else { //this resizes the width & height, artboard centered
            */      
                    
                    //uncomment above for fixing height as well
                if (abwidth < (6*72)) { 

                    idoc.artboards[i].artboardRect = [ableft, abBounds[1], abright, abBounds[3]]; } //this resizes the width only if it's less than specified above, artboard centered
                /** else { if (abheight < (6*72)) {
                        idoc.artboards[i].artboardRect = [abBounds[0], abtop, abBounds[2], abbottom]; //this resizes the height only if it's less than specified above, artboard centered
                    }}} */
                    //uncomment above for fixing height as well
                }

 

 

& Here's a version if you want it to check both width & height and fix only the dimension(s) that are smaller than the set thresholds.

 

#target Illustrator  

    var idoc  = app.activeDocument;

    var width = (7*72) //# of inches multiplied by ppi which is 72
    var height = (7*72) //uncomment this if you want to set height as well

    for (i=0; i<idoc.artboards.length; i++) {

            var abBounds = idoc.artboards[i].artboardRect; // the contents of this list are 0=left, 1=top, 2=right, 3=bottom


            var ableft = abBounds[0]; //these 4 vars just set the bounds of the artboard to readable names
            var abtop = abBounds[1];
            var abright = abBounds[2];
            var abbottom = abBounds[3];

            var abwidth = abBounds[2] - ableft; // these 2 vars calculate the width & height based on the bounds. right - left = width
            var abheight = abtop- abBounds[3]; // top - bottom = height

            var abctrx = abwidth/2+ableft; //these 2 vars help center the artboard
            var abctry = abtop-abheight/2; //uncomment this if you want to set height as well

            var ableft = abctrx-width/2; //these 4 vars calculate the new bounds of the artboard
            var abtop = abctry+height/2;  //uncomment this if you want to set height as well
            var abright = abctrx+width/2;
            var abbottom = abctry-height/2;  //uncomment this if you want to set height as well


           if (abwidth < (6*72) && abheight < (6*72)) { //this if statement detects if your width & height is under your set # of inches multiplied by ppi which is 72 (since illustrator measures in pixels). if it's lower, it resizes it to var width & var height shown above.

                idoc.artboards[i].artboardRect = [ableft, abtop, abright, abbottom]; } else { //this resizes the width & height, artboard centered
                 
                    
                    //uncomment above for fixing height as well
                if (abwidth < (6*72)) { 

                    idoc.artboards[i].artboardRect = [ableft, abBounds[1], abright, abBounds[3]]; } //this resizes the width only if it's less than specified above, artboard centered
                else { if (abheight < (6*72)) {
                        idoc.artboards[i].artboardRect = [abBounds[0], abtop, abBounds[2], abbottom]; //this resizes the height only if it's less than specified above, artboard centered
                    }}}
                    //uncomment above for fixing height as well
                }

 

 

Thanks for checking this out!

TOPICS
Scripting , SDK , Third party plugins , Tools

Views

1.9K

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Adobe
Community Expert ,
Sep 17, 2019 Sep 17, 2019

Copy link to clipboard

Copied

good job!! 

 

thanks for sharing!

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Sep 18, 2019 Sep 18, 2019

Copy link to clipboard

Copied

Thanks Carlos! Great to get a reply from the scripting legend I keep seeing everywhere haha!

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Sep 18, 2019 Sep 18, 2019

Copy link to clipboard

Copied

I'm Legend, so is Will Smith 🙂

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Apr 02, 2023 Apr 02, 2023

Copy link to clipboard

Copied

Thank you so much. That's so helpful. I do not know anything about Ai/jsx Scripts but still I am able to use this with the help of your comments in the code. Will you be able to help me for a specific request? I am just a designer and do not know much about these. I think it will be a simple one for you but not for me. I can pay you for that if that doesn't cost too much.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Apr 02, 2023 Apr 02, 2023

Copy link to clipboard

Copied

LATEST

Believe me! I have figured out a solution for my requirement with script from three people like you. I combined all those and created a solution for mine. You guys are great helping people like us. The beauty here is I don't know scripting. Your code is so detailed that helped me. Thank you so much for spending time for us.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines