Quantcast
Channel: Adobe Community: Message List - Photoshop Scripting
Viewing all articles
Browse latest Browse all 27456

Re: Shadow with .jsx

$
0
0

here it is with adding 300 to the canvas

 

app.activeDocument.suspendHistory("bcm_addShadow", "main()");

function main(){

   makeShadow( 15, 4.5, 2.49, 25.49, 70);// these values are procents

   //arg1: the x procent to be added to the elised selection relative to the width of the layer

   //arg2: the y procent to be added to the elised selection relative to the hight of the layer// obsolete

   //arg3: the blur procent

   //arg4: the motion blur procent

   //arg5: the opacity procent

}

function makeShadow( xPrc, yPrc, blurPrc, mBlurPrc, shOpacPrc){

 

 

// ======================================================= first add 300 px around

  var idCnvS = charIDToTypeID( "CnvS" );

      var desc9 = new ActionDescriptor();

      var idRltv = charIDToTypeID( "Rltv" );

      desc9.putBoolean( idRltv, true );

      var idWdth = charIDToTypeID( "Wdth" );

      var idPxl = charIDToTypeID( "#Pxl" );

      desc9.putUnitDouble( idWdth, idPxl, 300.000000 );

      var idHght = charIDToTypeID( "Hght" );

      var idPxl = charIDToTypeID( "#Pxl" );

      desc9.putUnitDouble( idHght, idPxl, 300.000000 );

      var idHrzn = charIDToTypeID( "Hrzn" );

      var idHrzL = charIDToTypeID( "HrzL" );

      var idCntr = charIDToTypeID( "Cntr" );

      desc9.putEnumerated( idHrzn, idHrzL, idCntr );

      var idVrtc = charIDToTypeID( "Vrtc" );

      var idVrtL = charIDToTypeID( "VrtL" );

      var idCntr = charIDToTypeID( "Cntr" );

      desc9.putEnumerated( idVrtc, idVrtL, idCntr );

  executeAction( idCnvS, desc9, DialogModes.NO );

 

 

 

 

 

 

    var btLayer = app.activeDocument.activeLayer;

    var lyrN = btLayer.name;

  var lb = getLBounds();

  var lw = parseFloat(lb.right) - parseFloat(lb.left);

  var lh = parseFloat(lb.bottom) - parseFloat(lb.top);

  var percW = (lw * xPrc) / 100;

  var percH = (lh * yPrc) / 100;

 

 

  //==================getting the bottom bounds

  var lidx = getSelectedLayersIdx();

  var percWT = (lw * 20) / 100;

  var percHT = (lh * 20) / 100;

  makeSquareSelection( lb.bottom - percHT, lb.left, lb.bottom, lb.right);

  app.activeDocument.selection.invert();

  makeShadowLayer();

  var tlidx = getSelectedLayersIdx();

 

 

  selectLayerTranspByIDX(parseInt(lidx));

  substractLayerTranspByIDX(parseInt(tlidx));

  // =======================================================delete temp layer

  var idDlt = charIDToTypeID( "Dlt " );

      var desc240 = new ActionDescriptor();

      var idnull = charIDToTypeID( "null" );

          var ref221 = new ActionReference();

          var idLyr = charIDToTypeID( "Lyr " );

          var idOrdn = charIDToTypeID( "Ordn" );

          var idTrgt = charIDToTypeID( "Trgt" );

          ref221.putEnumerated( idLyr, idOrdn, idTrgt );

      desc240.putReference( idnull, ref221 );

  executeAction( idDlt, desc240, DialogModes.NO );

  var lcb = app.activeDocument.selection.bounds;

  lcbO = { left:parseInt(lcb[0]), top:parseInt(lcb[1]), right:parseInt(lcb[2]), bottom:parseInt(lcb[3]) };

  app.activeDocument.selection.deselect();

  //=============finished finding the bottom bonds

  var selW = (percH, lcbO.right + percW)-(lcbO.left - percW);

  var pH = (selW / 6.77)/2;//keepeng all the elipsoids to the same ratio

 

  makeElipsoidSelection( lcbO.bottom - pH, lcbO.left - percW, lcbO.bottom + pH, lcbO.right + percW);

  offsetSelection( -percH/2, 0 );//rising a bit the selection

  makeShadowLayer();

 

 

  // =======================================================

  var idnewPlacedLayer = stringIDToTypeID( "newPlacedLayer" );

  executeAction( idnewPlacedLayer, undefined, DialogModes.NO );

 

 

  var selH = (lb.right + percH)-(lb.left - percH);

  var selcH = (lcbO.right + percH)-(lcbO.left - percH);

  // alert(selH)

  var blurPercH = (selcH * blurPrc) / 100;

  blur(blurPercH);

  var MblurPercH = (selcH * mBlurPrc) / 100;

  mtnBlur( parseInt(MblurPercH));

 

 

    // =======================================================move layer down

    var idmove = charIDToTypeID( "move" );

        var desc312 = new ActionDescriptor();

        var idnull = charIDToTypeID( "null" );

            var ref283 = new ActionReference();

            var idLyr = charIDToTypeID( "Lyr " );

            var idOrdn = charIDToTypeID( "Ordn" );

            var idTrgt = charIDToTypeID( "Trgt" );

            ref283.putEnumerated( idLyr, idOrdn, idTrgt );

        desc312.putReference( idnull, ref283 );

        var idT = charIDToTypeID( "T   " );

            var ref284 = new ActionReference();

            var idLyr = charIDToTypeID( "Lyr " );

            var idOrdn = charIDToTypeID( "Ordn" );

            var idPrvs = charIDToTypeID( "Prvs" );

            ref284.putEnumerated( idLyr, idOrdn, idPrvs );

        desc312.putReference( idT, ref284 );

    executeAction( idmove, desc312, DialogModes.NO );

 

 

    app.activeDocument.activeLayer.name = lyrN +"_shadow";//rename shadowlayer

// =======================================================set opacity

        var idsetd = charIDToTypeID( "setd" );

        var desc317 = new ActionDescriptor();

        var idnull = charIDToTypeID( "null" );

            var ref288 = new ActionReference();

            var idLyr = charIDToTypeID( "Lyr " );

            var idOrdn = charIDToTypeID( "Ordn" );

            var idTrgt = charIDToTypeID( "Trgt" );

            ref288.putEnumerated( idLyr, idOrdn, idTrgt );

        desc317.putReference( idnull, ref288 );

        var idT = charIDToTypeID( "T   " );

            var desc318 = new ActionDescriptor();

            var idOpct = charIDToTypeID( "Opct" );

            var idPrc = charIDToTypeID( "#Prc" );

            desc318.putUnitDouble( idOpct, idPrc, shOpacPrc );

        var idLyr = charIDToTypeID( "Lyr " );

        desc317.putObject( idT, idLyr, desc318 );

    executeAction( idsetd, desc317, DialogModes.NO );

 

 

    app.activeDocument.activeLayer = btLayer;

 

 

 

}

 

 

 

function getLBounds(){

   var ref = new ActionReference();

  ref.putEnumerated( charIDToTypeID("Lyr ") , charIDToTypeID( "Ordn" ), charIDToTypeID( "Trgt" ) );

  desc1 = executeActionGet(ref);

  desc1 = desc1.getObjectValue(stringIDToTypeID('bounds'));

  desc1Top = desc1.getUnitDoubleValue(stringIDToTypeID('top'));

  desc1Bottom = desc1.getUnitDoubleValue(stringIDToTypeID('bottom'));

  desc1Left = desc1.getUnitDoubleValue(stringIDToTypeID('left'));

  desc1Right = desc1.getUnitDoubleValue(stringIDToTypeID('right'));

  rObj = {top:desc1Top, left:desc1Left, bottom:desc1Bottom, right:desc1Right};

  return rObj;

}

function selectLayerTranspByIDX( idx ){

    var idsetd = charIDToTypeID( "setd" );

      var desc205 = new ActionDescriptor();

      var idnull = charIDToTypeID( "null" );

          var ref179 = new ActionReference();

          var idChnl = charIDToTypeID( "Chnl" );

          var idfsel = charIDToTypeID( "fsel" );

          ref179.putProperty( idChnl, idfsel );

      desc205.putReference( idnull, ref179 );

      var idT = charIDToTypeID( "T   " );

          var ref180 = new ActionReference();

          var idChnl = charIDToTypeID( "Chnl" );

          var idChnl = charIDToTypeID( "Chnl" );

          var idTrsp = charIDToTypeID( "Trsp" );

          ref180.putEnumerated( idChnl, idChnl, idTrsp );

          var idLyr = charIDToTypeID( "Lyr " );

          ref180.putIndex( idLyr, idx );

      desc205.putReference( idT, ref180 );

  executeAction( idsetd, desc205, DialogModes.NO );

}

function substractLayerTranspByIDX( idx ){

  var idSbtr = charIDToTypeID( "Sbtr" );

    var desc213 = new ActionDescriptor();

    var idnull = charIDToTypeID( "null" );

        var ref193 = new ActionReference();

        var idChnl = charIDToTypeID( "Chnl" );

        var idChnl = charIDToTypeID( "Chnl" );

        var idTrsp = charIDToTypeID( "Trsp" );

        ref193.putEnumerated( idChnl, idChnl, idTrsp );

        var idLyr = charIDToTypeID( "Lyr " );

        ref193.putIndex( idLyr, idx );

    desc213.putReference( idnull, ref193 );

    var idFrom = charIDToTypeID( "From" );

        var ref194 = new ActionReference();

        var idChnl = charIDToTypeID( "Chnl" );

        var idfsel = charIDToTypeID( "fsel" );

        ref194.putProperty( idChnl, idfsel );

    desc213.putReference( idFrom, ref194 );

executeAction( idSbtr, desc213, DialogModes.NO );

 

 

}

function makeSquareSelection( top, left, btom, right){

var idsetd = charIDToTypeID( "setd" );

    var desc167 = new ActionDescriptor();

    var idnull = charIDToTypeID( "null" );

        var ref135 = new ActionReference();

        var idChnl = charIDToTypeID( "Chnl" );

        var idfsel = charIDToTypeID( "fsel" );

        ref135.putProperty( idChnl, idfsel );

    desc167.putReference( idnull, ref135 );

    var idT = charIDToTypeID( "T   " );

        var desc168 = new ActionDescriptor();

        var idTop = charIDToTypeID( "Top " );

        var idPxl = charIDToTypeID( "#Pxl" );

        desc168.putUnitDouble( idTop, idPxl, top );

        var idLeft = charIDToTypeID( "Left" );

        var idPxl = charIDToTypeID( "#Pxl" );

        desc168.putUnitDouble( idLeft, idPxl, left );

        var idBtom = charIDToTypeID( "Btom" );

        var idPxl = charIDToTypeID( "#Pxl" );

        desc168.putUnitDouble( idBtom, idPxl, btom );

        var idRght = charIDToTypeID( "Rght" );

        var idPxl = charIDToTypeID( "#Pxl" );

        desc168.putUnitDouble( idRght, idPxl, right );

    var idRctn = charIDToTypeID( "Rctn" );

    desc167.putObject( idT, idRctn, desc168 );

executeAction( idsetd, desc167, DialogModes.NO );

 

 

}

function makeElipsoidSelection( top, left, btom, right){

var idsetd = charIDToTypeID( "setd" );

    var desc15 = new ActionDescriptor();

    var idnull = charIDToTypeID( "null" );

        var ref10 = new ActionReference();

        var idChnl = charIDToTypeID( "Chnl" );

        var idfsel = charIDToTypeID( "fsel" );

        ref10.putProperty( idChnl, idfsel );

    desc15.putReference( idnull, ref10 );

    var idT = charIDToTypeID( "T   " );

        var desc16 = new ActionDescriptor();

        var idTop = charIDToTypeID( "Top " );

        var idPxl = charIDToTypeID( "#Pxl" );

        desc16.putUnitDouble( idTop, idPxl, parseInt(top) );

        var idLeft = charIDToTypeID( "Left" );

        var idPxl = charIDToTypeID( "#Pxl" );

        desc16.putUnitDouble( idLeft, idPxl, parseInt(left) );

        var idBtom = charIDToTypeID( "Btom" );

        var idPxl = charIDToTypeID( "#Pxl" );

        desc16.putUnitDouble( idBtom, idPxl, parseInt(btom) );

        var idRght = charIDToTypeID( "Rght" );

        var idPxl = charIDToTypeID( "#Pxl" );

        desc16.putUnitDouble( idRght, idPxl, parseInt(right) );

    var idElps = charIDToTypeID( "Elps" );

    desc15.putObject( idT, idElps, desc16 );

    var idAntA = charIDToTypeID( "AntA" );

    desc15.putBoolean( idAntA, true );

executeAction( idsetd, desc15, DialogModes.NO );

}

function makeShadowLayer(){

    // =======================================================

var idMk = charIDToTypeID( "Mk  " );

    var desc169 = new ActionDescriptor();

    var idnull = charIDToTypeID( "null" );

        var ref153 = new ActionReference();

        var idLyr = charIDToTypeID( "Lyr " );

        ref153.putClass( idLyr );

    desc169.putReference( idnull, ref153 );

executeAction( idMk, desc169, DialogModes.NO );

 

 

var blck = new SolidColor();

blck.rgb.red = 0;

blck.rgb.green = 0;

blck.rgb.blue = 0;

 

 

app.activeDocument.selection.fill(blck);

app.activeDocument.selection.deselect();

}

function blur( ss ){

  var idGsnB = charIDToTypeID( "GsnB" );

    var desc65 = new ActionDescriptor();

    var idRds = charIDToTypeID( "Rds " );

    var idPxl = charIDToTypeID( "#Pxl" );

    desc65.putUnitDouble( idRds, idPxl, ss );

executeAction( idGsnB, desc65, DialogModes.NO );

}

function mtnBlur( ss ){

    var idMtnB = charIDToTypeID( "MtnB" );

    var desc226 = new ActionDescriptor();

    var idAngl = charIDToTypeID( "Angl" );

    desc226.putInteger( idAngl, 0 );

    var idDstn = charIDToTypeID( "Dstn" );

    var idPxl = charIDToTypeID( "#Pxl" );

    desc226.putUnitDouble( idDstn, idPxl, ss );

executeAction( idMtnB, desc226, DialogModes.NO );

}

function getSelectedLayersIdx(){// get the selected layers index( positon in layer editor)

     var selectedLayers = new Array;

     var ref = new ActionReference();

     ref.putEnumerated( charIDToTypeID('Dcmn'), charIDToTypeID('Ordn'), charIDToTypeID('Trgt') );

     var desc = executeActionGet(ref);

     var add = 1;

     if(hasBackground()){alert('hBck');add = 0}

     if( desc.hasKey( stringIDToTypeID( 'targetLayers' ) ) ){

          desc = desc.getList( stringIDToTypeID( 'targetLayers' ));

          var c = desc.count

          var selectedLayers = new Array();

          for(var i=0;i<c;i++){

               selectedLayers.push(  (desc.getReference( i ).getIndex()) + add);

          }

     }else{

          var ref = new ActionReference();

          ref.putProperty( charIDToTypeID('Prpr') , charIDToTypeID( 'ItmI' ));

          ref.putEnumerated( charIDToTypeID('Lyr '), charIDToTypeID('Ordn'), charIDToTypeID('Trgt') );

          srs = hasBackground()?executeActionGet(ref).getInteger(charIDToTypeID( 'ItmI' ))-1:executeActionGet(ref).getInteger(charIDToTypeID( 'ItmI' ));

          selectedLayers.push( srs);

     }

     return selectedLayers;

}

function hasBackground(){// function to check if there is a background layer

    var res = undefined;

    try{

        var ref = new ActionReference();

        ref.putProperty( charIDToTypeID("Prpr") , charIDToTypeID("Nm  "));

        ref.putIndex( charIDToTypeID("Lyr "), 0 );

        executeActionGet(ref).getString(charIDToTypeID("Nm  ") );

        res = true;

    }catch(e){ res = false}

    return res;

}

function offsetSelection( x, y ){

  var idTrnf = charIDToTypeID( "Trnf" );

    var desc356 = new ActionDescriptor();

    var idnull = charIDToTypeID( "null" );

        var ref314 = new ActionReference();

        var idChnl = charIDToTypeID( "Chnl" );

        var idfsel = charIDToTypeID( "fsel" );

        ref314.putProperty( idChnl, idfsel );

    desc356.putReference( idnull, ref314 );

    var idFTcs = charIDToTypeID( "FTcs" );

    var idQCSt = charIDToTypeID( "QCSt" );

    var idQcsa = charIDToTypeID( "Qcsa" );

    desc356.putEnumerated( idFTcs, idQCSt, idQcsa );

    var idOfst = charIDToTypeID( "Ofst" );

        var desc357 = new ActionDescriptor();

        var idHrzn = charIDToTypeID( "Hrzn" );

        var idPxl = charIDToTypeID( "#Pxl" );

        desc357.putUnitDouble( idHrzn, idPxl, y );

        var idVrtc = charIDToTypeID( "Vrtc" );

        var idPxl = charIDToTypeID( "#Pxl" );

        desc357.putUnitDouble( idVrtc, idPxl, x );

    var idOfst = charIDToTypeID( "Ofst" );

    desc356.putObject( idOfst, idOfst, desc357 );

    var idIntr = charIDToTypeID( "Intr" );

    var idIntp = charIDToTypeID( "Intp" );

    var idBcbc = charIDToTypeID( "Bcbc" );

    desc356.putEnumerated( idIntr, idIntp, idBcbc );

executeAction( idTrnf, desc356, DialogModes.NO );

 

 

}


Viewing all articles
Browse latest Browse all 27456

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>