/* Got questions improvements? please do ask or share
regards Kristian Andersen krilleandersen@gmail.com
*/
var oldHH= 0;
var startRulerUnits = app.preferences.rulerUnits;
app.preferences.rulerUnits = Units.PIXELS;
var createNewArtboard = function(w,h,t,n) {
var ww=parseFloat(w);//+'.'+000000;
var hh=parseFloat(h);//+'.'+000000;
var tt = parseFloat(oldHH);//+ '.'+000000;
var nme=w+'x'+h;
//alert(oldHH)
//Make the Artboard
// =======================================================
var idMk = charIDToTypeID( "Mk " );
var desc510 = new ActionDescriptor();
var idnull = charIDToTypeID( "null" );
var ref39 = new ActionReference();
var idartboardSection = stringIDToTypeID( "artboardSection" );
ref39.putClass( idartboardSection );
desc510.putReference( idnull, ref39 );
var idlayerSectionStart = stringIDToTypeID( "layerSectionStart" );
desc510.putInteger( idlayerSectionStart, 5 );
var idlayerSectionEnd = stringIDToTypeID( "layerSectionEnd" );
desc510.putInteger( idlayerSectionEnd, 6 );
var idNm = charIDToTypeID( "Nm " );
desc510.putString( idNm, ""+nme+"" );
var idartboardRect = stringIDToTypeID( "artboardRect" );
var desc511 = new ActionDescriptor();
var idTop = charIDToTypeID( "Top " );
desc511.putDouble( idTop, 0.000000 );
var idLeft = charIDToTypeID( 'Left' );
desc511.putDouble( idLeft, 0.000000);
var idBtom = charIDToTypeID( 'Btom' );
desc511.putDouble( idBtom, parseInt(hh)); //<--- Height
var idRght = charIDToTypeID( 'Rght' );
desc511.putDouble( idRght, parseInt(ww));//<--- Width
var idclassFloatRect = stringIDToTypeID( "classFloatRect" );
desc510.putObject( idartboardRect, idclassFloatRect, desc511 );
executeAction( idMk, desc510, DialogModes.NO );
//Change artboard default name
// =======================================================
var idsetd = charIDToTypeID( "setd" );
var desc907 = new ActionDescriptor();
var idnull = charIDToTypeID( "null" );
var ref132 = new ActionReference();
var idLyr = charIDToTypeID( "Lyr " );
var idOrdn = charIDToTypeID( "Ordn" );
var idTrgt = charIDToTypeID( "Trgt" );
ref132.putEnumerated( idLyr, idOrdn, idTrgt );
desc907.putReference( idnull, ref132 );
var idT = charIDToTypeID( "T " );
var desc908 = new ActionDescriptor();
var idNm = charIDToTypeID( "Nm " );
desc908.putString( idNm, ""+'xxx_'+'oooo'+'_'+nme+ "" ); //<-- artboard name
var idLyr = charIDToTypeID( "Lyr " );
desc907.putObject( idT, idLyr, desc908 );
executeAction( idsetd, desc907, DialogModes.NO );
//Space out artboard
// =======================================================
var ideditArtboardEvent = stringIDToTypeID( "editArtboardEvent" );
var desc95 = new ActionDescriptor();
var idnull = charIDToTypeID( "null" );
var ref12 = new ActionReference();
var idLyr = charIDToTypeID( "Lyr " );
var idOrdn = charIDToTypeID( 'Ordn' );
var idTrgt = charIDToTypeID( 'Trgt' );
ref12.putEnumerated( idLyr, idOrdn, idTrgt );
desc95.putReference( idnull, ref12 );
var idartboard = stringIDToTypeID( "artboard" );
var desc96 = new ActionDescriptor();
var idartboardRect = stringIDToTypeID( "artboardRect" );
var desc97 = new ActionDescriptor();
var idTop = charIDToTypeID( "Top " );
desc97.putDouble( idTop, tt ); //<-- artboard y
var idLeft = charIDToTypeID( 'Left' );
desc97.putDouble( idLeft, 0.000000 );//<-- artboard x
var idBtom = charIDToTypeID( 'Btom' );
desc97.putDouble( idBtom, hh );
var idRght = charIDToTypeID( 'Rght' );
desc97.putDouble( idRght, ww );
var idclassFloatRect = stringIDToTypeID( "classFloatRect" );
desc96.putObject( idartboardRect, idclassFloatRect, desc97 );
var idguideIDs = stringIDToTypeID( "guideIDs" );
var list10 = new ActionList();
desc96.putList( idguideIDs, list10 );
var idartboardPresetName = stringIDToTypeID( "artboardPresetName" );
desc96.putString( idartboardPresetName, ""+nme+"" );
var idClr = charIDToTypeID( "Clr " );
var desc98 = new ActionDescriptor();
var idRd = charIDToTypeID( "Rd " );
desc98.putDouble( idRd, 255.000000 );
var idGrn = charIDToTypeID( "Grn " );
desc98.putDouble( idGrn, 255.000000 );
var idBl = charIDToTypeID( "Bl " );
desc98.putDouble( idBl, 255.000000 );
var idRGBC = charIDToTypeID( 'RGBC' );
desc96.putObject( idClr, idRGBC, desc98 );
var idartboardBackgroundType = stringIDToTypeID( "artboardBackgroundType" );
desc96.putInteger( idartboardBackgroundType, 3 ); //<-- artboardBackgroundType 1 = white, 2 = black, 3 = transparent
var idartboard = stringIDToTypeID( "artboard" );
desc95.putObject( idartboard, idartboard, desc96 );
var idchangeSizes = stringIDToTypeID( "changeSizes" );
desc95.putInteger( idchangeSizes, 5 );
executeAction( ideditArtboardEvent, desc95, DialogModes.NO );
oldHH = parseFloat(oldHH+parseFloat(h)+50); //<-- calculate artboart y position (artboard height + pervious artboard height+50pixels)
};
function makeshithappen(){
//banner sizes /,
var sizes = [[60,600],[225,265],[450,100],[478,235],[620,540],[620,540],[640,340],[640,340],[851,315],[900,200],[1200,628],[1200,717],[1242,250],[1260,420],[1350,300],[1434,220],[1474,180],[1500,500],[1800,400],[2500,350]];
var count=1;
var sizeW;
var sizeH;
for(var i = 0; i < sizes.length; i++) {
var size = sizes[i];
for(var j = 0; j < size.length; j++) {
if(count==1){
sizeW = size[j];
}
if(count==2){
sizeH = size[j] ;
createNewArtboard(sizeW,sizeH,(sizeH+sizeH),size);
count=0;
}
count++
}
}
}
makeshithappen()