You could give this a try: // add layer with stroke and text with measurements of selection; // 2011, use it at your own risk; #target photoshop try { var state = app.activeDocument.activeHistoryState; app.activeDocument.selection.deselect(); if (app.activeDocument.activeHistoryState != state) { app.activeDocument.activeHistoryState = state var check = true; } else { var check = false }; } catch (e) {var check = false}; // if document and selection; if (check == true) { var originalRulerUnits = preferences.rulerUnits; preferences.rulerUnits = Units.PIXELS; var originalResolution = app.activeDocument.resolution; var myDocument = app.activeDocument; myDocument.resizeImage (undefined, undefined, 72, ResampleMethod.NONE); // get selection measurements; var theBounds = myDocument.selection.bounds; var width = theBounds[2] - theBounds[0]; var height = theBounds[3] - theBounds[1]; // make layer; var theLayer = makeFillLayer(width+"x"+height, 0, 0, 0, 0); theLayer.fillOpacity = 0; addStroke(); // create a text layer; var textLayer = myDocument.artLayers.add(); textLayer.kind = LayerKind.TEXT; textLayer.name = width+" x "+height; var myTextRef = textLayer.textItem; myTextRef.size = 12 * originalResolution / 72; myTextRef.font = "Arial-BoldMT"; //Set text colour in RGB values var newColor = new SolidColor(); newColor.rgb.red = 0; newColor.rgb.green = 0; newColor.rgb.blue = 0; myTextRef.color = newColor; myTextRef.justification = Justification.RIGHT; myTextRef.kind = TextType.POINTTEXT; myTextRef.position = [theBounds[2], theBounds[1] - 10]; myTextRef.contents = width+" x "+height; textLayer.blendMode = BlendMode.NORMAL; textLayer.opacity = 100; // reset; preferences.rulerUnits = originalRulerUnits; myDocument.resizeImage (undefined, undefined, originalResolution, ResampleMethod.NONE); }; ////// the fill-layer-function ////// function makeFillLayer (name, b, c, d, e) { var idMk = charIDToTypeID( "Mk " ); var desc6 = new ActionDescriptor(); var idnull = charIDToTypeID( "null" ); var ref2 = new ActionReference(); var idcontentLayer = stringIDToTypeID( "contentLayer" ); ref2.putClass( idcontentLayer ); desc6.putReference( idnull, ref2 ); var idUsng = charIDToTypeID( "Usng" ); var desc7 = new ActionDescriptor(); var idNm = charIDToTypeID( "Nm " ); desc7.putString( idNm, name ); var idType = charIDToTypeID( "Type" ); var desc8 = new ActionDescriptor(); var idClr = charIDToTypeID( "Clr " ); var desc9 = new ActionDescriptor(); var idCyn = charIDToTypeID( "Cyn " ); desc9.putDouble( idCyn, b ); var idMgnt = charIDToTypeID( "Mgnt" ); desc9.putDouble( idMgnt, c ); var idYlw = charIDToTypeID( "Ylw " ); desc9.putDouble( idYlw, d ); var idBlck = charIDToTypeID( "Blck" ); desc9.putDouble( idBlck, e ); var idCMYC = charIDToTypeID( "CMYC" ); desc8.putObject( idClr, idCMYC, desc9 ); var idsolidColorLayer = stringIDToTypeID( "solidColorLayer" ); desc7.putObject( idType, idsolidColorLayer, desc8 ); var idcontentLayer = stringIDToTypeID( "contentLayer" ); desc6.putObject( idUsng, idcontentLayer, desc7 ); executeAction( idMk, desc6, DialogModes.NO ); return app.activeDocument.activeLayer }; ////// stroke ////// function addStroke () { // ======================================================= var idsetd = charIDToTypeID( "setd" ); var desc5 = new ActionDescriptor(); var idnull = charIDToTypeID( "null" ); var ref2 = new ActionReference(); var idPrpr = charIDToTypeID( "Prpr" ); var idLefx = charIDToTypeID( "Lefx" ); ref2.putProperty( idPrpr, idLefx ); var idLyr = charIDToTypeID( "Lyr " ); var idOrdn = charIDToTypeID( "Ordn" ); var idTrgt = charIDToTypeID( "Trgt" ); ref2.putEnumerated( idLyr, idOrdn, idTrgt ); desc5.putReference( idnull, ref2 ); var idT = charIDToTypeID( "T " ); var desc6 = new ActionDescriptor(); var idScl = charIDToTypeID( "Scl " ); var idPrc = charIDToTypeID( "#Prc" ); desc6.putUnitDouble( idScl, idPrc, 416.666667 ); var idFrFX = charIDToTypeID( "FrFX" ); var desc7 = new ActionDescriptor(); var idenab = charIDToTypeID( "enab" ); desc7.putBoolean( idenab, true ); var idStyl = charIDToTypeID( "Styl" ); var idFStl = charIDToTypeID( "FStl" ); var idInsF = charIDToTypeID( "InsF" ); desc7.putEnumerated( idStyl, idFStl, idInsF ); var idPntT = charIDToTypeID( "PntT" ); var idFrFl = charIDToTypeID( "FrFl" ); var idSClr = charIDToTypeID( "SClr" ); desc7.putEnumerated( idPntT, idFrFl, idSClr ); var idMd = charIDToTypeID( "Md " ); var idBlnM = charIDToTypeID( "BlnM" ); var idNrml = charIDToTypeID( "Nrml" ); desc7.putEnumerated( idMd, idBlnM, idNrml ); var idOpct = charIDToTypeID( "Opct" ); var idPrc = charIDToTypeID( "#Prc" ); desc7.putUnitDouble( idOpct, idPrc, 100.000000 ); var idSz = charIDToTypeID( "Sz " ); var idPxl = charIDToTypeID( "#Pxl" ); desc7.putUnitDouble( idSz, idPxl, 1.000000 ); var idClr = charIDToTypeID( "Clr " ); var desc8 = new ActionDescriptor(); var idRd = charIDToTypeID( "Rd " ); desc8.putDouble( idRd, 0.000000 ); var idGrn = charIDToTypeID( "Grn " ); desc8.putDouble( idGrn, 0.000000 ); var idBl = charIDToTypeID( "Bl " ); desc8.putDouble( idBl, 0.000000 ); var idRGBC = charIDToTypeID( "RGBC" ); desc7.putObject( idClr, idRGBC, desc8 ); var idFrFX = charIDToTypeID( "FrFX" ); desc6.putObject( idFrFX, idFrFX, desc7 ); var idLefx = charIDToTypeID( "Lefx" ); desc5.putObject( idT, idLefx, desc6 ); executeAction( idsetd, desc5, DialogModes.NO ); };
... View more