6 Replies Latest reply on Jul 25, 2014 8:45 PM by Muppet Mark

    Detecting artboard size for batch export


      Hello all,


      At the moment I have an Illustrator document with multiple artboards of different sizes. I am trying to write a script that loops through the artboards, detects the artboard width, and exports each one to PNG with a custom scale depending on said width. From what I've seen in the json reference library, it looks like artboard.width is not an exposed property. The only alternative approach I can think of is saving each artboard out as a seperate AI file, then opening the files and resizing each one according to document width? Any help would be greatly appreciated.

        • 1. Re: Detecting artboard size for batch export
          Larry G. Schneider Adobe Community Professional & MVP

          Look at the artboardRect, which is the size and position of the artboard and artboard name which you can use to address an individual artboard.

          • 2. Re: Detecting artboard size for batch export
            jopri Level 1

            Thank you! Is there an example of proper syntax anywhere so I know how to grab that width properly?

            • 3. Re: Detecting artboard size for batch export
              Larry G. Schneider Adobe Community Professional & MVP

              Since the artboardRect is a subclass of Rectangle, use the calls from that class which has a width property.

              • 4. Re: Re: Detecting artboard size for batch export
                jopri Level 1

                I'm admittedly a bit new to this scripting. I have the following script, however my function completely ignores all of my 'if else' conditions and just overwrites each artboard as a PNG at 150% scaling over and over with the same name.


                var docRef = app.activeDocument;  
                var destFolder = Folder.selectDialog();
                var num_artboards = docRef.artboards.length;
                var i = 0;
                var ab = docRef.artboards[0];  
                var abBounds = ab.artboardRect;// left, top, right, bottom  
                var ableft = abBounds[0];
                var abtop = abBounds[1];
                var abright = abBounds[2];  
                var abbottom = abBounds[3];  
                var abwidth = abright - ableft; 
                var abheight = abtop- abbottom; 
                var scale100options = new ExportOptionsPNG24();  
                var scale125options = new ExportOptionsPNG24(); 
                var scale150options = new ExportOptionsPNG24(); 
                var scale200options = new ExportOptionsPNG24(); 
                var scale300options = new ExportOptionsPNG24();  
                var optionsprompt = new ExportOptionsPNG24();  
                var type = ExportType.PNG24;  
                //** Scaling Options **//
                // Scale 100 Options
                scale100options.artBoardClipping = true;  
                scale100options.matte = false;  
                scale100options.horizontalScale = scale100options.verticalScale = 100;
                // Scale 125 Options
                scale125options.artBoardClipping = true;  
                scale125options.matte = false;  
                scale125options.horizontalScale = scale125options.verticalScale = 125;
                // Scale 150 Options
                scale150options.artBoardClipping = true;  
                scale150options.matte = false;  
                scale150options.horizontalScale = scale150options.verticalScale = 150;
                // Scale 200 Options
                scale200options.artBoardClipping = true;  
                scale200options.matte = false;  
                scale200options.horizontalScale = scale200options.verticalScale = 200;
                // Scale 300 Options
                scale300options.artBoardClipping = true;  
                scale300options.matte = false;  
                scale300options.horizontalScale = scale300options.verticalScale = 300;
                // Loop //
                for (var i = 0; i < num_artboards; i++ ) {  
                    detectSizes ();
                function detectSizes () {
                    var destFile = new File(destFolder + "/" + docRef.name + docRef.artboards[i].name);    
                    if ( abwidth = 320 ) {
                        app.activeDocument.exportFile (destFile, type, scale150options );  
                    else if ( abwidth = 360 ) {
                        app.activeDocument.exportFile (destFile, type, scale300options );  
                    else if ( abwidth = 480 ) {
                        app.activeDocument.exportFile (destFile, type, scale150options );  
                    else if ( abwidth = 540 ) {
                        app.activeDocument.exportFile (destFile, type, scale200options );  
                    else if ( abwidth = 640 ) {
                        app.activeDocument.exportFile (destFile, type, scale125options );  
                    else if ( abwidth = 1366 ) {
                        app.activeDocument.exportFile (destFile, type, scale100options );  
                    else if ( abwidth = 2560 ) {
                        app.activeDocument.exportFile (destFile, type, scale100options );  
                    else {
                        app.activeDocument.exportFile (destFile, type, scale100options );  
                • 5. Re: Re: Detecting artboard size for batch export
                  Larry G. Schneider Adobe Community Professional & MVP

                  Since I don't have any documents with artboards size as you do my experiment uses the last option and exports the files with the name of the file and the name of the artboard. You might try setting the measurement units you are using. Another thing is you might have to coerce the returned width to the number you want to see by dumping part after the decimal (unless they are exact sizes in points/pixels and snapped to a grid).

                  • 6. Re: Detecting artboard size for batch export
                    Muppet Mark Level 5

                    I only quick glance at your script… but I see several errors straight away…


                    You only use the bounds of the first artboards[0]…? if they is all different then this must be inside the loop…? ( as size for each )


                    Just create the one options object and only change the scaling property for each…? ( you have far more than you need here )


                    Lastly detectSizes() is a function… You have passed it nothing in arguments terms so your variables are out of scope…? ( it no have the slightest idea what scale options are )