5 Replies Latest reply on Oct 19, 2011 8:55 AM by c.pfaffenbichler

    want to apply layer mask

    sasientry Level 1

      Hello all

       

      when i open the image

       

      i want to change background layer and name it source

       

      after i want to apply layermask selection from path

        • 1. Re: want to apply layer mask
          c.pfaffenbichler Level 9

          Why not a Vector Mask?

          Anyway, this might work – it uses the first path:

          // convert background layer and add layer mask from the first path;
          // 2011, use it at your own risk;
          #target photoshop;
          if (app.documents.length > 0 && app.activeDocument.pathItems.length > 0) {
          var myDocument = app.activeDocument;
          var theLayer = myDocument.layers[myDocument.layers.length - 1];
          if (theLayer.isBackgroundLayer == true) {theLayer.isBackgroundLayer = false};
          theLayer.name = "source";
          var thePath = myDocument.pathItems[myDocument.pathItems.length - 1];
          thePath.makeSelection(0, true, SelectionType.REPLACE);
          myDocument.activeLayer = theLayer;
          // make layer mask;
          var idMk = charIDToTypeID( "Mk  " );
          var desc168 = new ActionDescriptor();
          var idNw = charIDToTypeID( "Nw  " );
          var idChnl = charIDToTypeID( "Chnl" );
          desc168.putClass( idNw, idChnl );
          var idAt = charIDToTypeID( "At  " );
          var ref99 = new ActionReference();
          var idChnl = charIDToTypeID( "Chnl" );
          var idChnl = charIDToTypeID( "Chnl" );
          var idMsk = charIDToTypeID( "Msk " );
          ref99.putEnumerated( idChnl, idChnl, idMsk );
          desc168.putReference( idAt, ref99 );
          var idUsng = charIDToTypeID( "Usng" );
          var idUsrM = charIDToTypeID( "UsrM" );
          var idRvlS = charIDToTypeID( "RvlS" );
          desc168.putEnumerated( idUsng, idUsrM, idRvlS );
          executeAction( idMk, desc168, DialogModes.ALL );
          };
          
          • 2. Re: want to apply layer mask
            sasientry Level 1

            how to apply layer mask without selection in soure layer

            • 3. Re: want to apply layer mask
              c.pfaffenbichler Level 9

              Do you mean a Vector Mask?

              • 4. Re: want to apply layer mask
                sasientry Level 1

                no only layer mask without selection

                 

                example = color fill

                • 5. Re: want to apply layer mask
                  c.pfaffenbichler Level 9

                  So create a Reveal All-Layer Mask

                   

                  var idMk = charIDToTypeID( "Mk  " );
                  var desc166 = new ActionDescriptor();
                  var idNw = charIDToTypeID( "Nw  " );
                  var idChnl = charIDToTypeID( "Chnl" );
                  desc166.putClass( idNw, idChnl );
                  var idAt = charIDToTypeID( "At  " );
                  var ref97 = new ActionReference();
                  var idChnl = charIDToTypeID( "Chnl" );
                  var idChnl = charIDToTypeID( "Chnl" );
                  var idMsk = charIDToTypeID( "Msk " );
                  ref97.putEnumerated( idChnl, idChnl, idMsk );
                  desc166.putReference( idAt, ref97 );
                  var idUsng = charIDToTypeID( "Usng" );
                  var idUsrM = charIDToTypeID( "UsrM" );
                  var idRvlA = charIDToTypeID( "RvlA" );
                  desc166.putEnumerated( idUsng, idUsrM, idRvlA );
                  executeAction( idMk, desc166, DialogModes.ALL );
                  

                   

                  and use the method fillPath.

                   

                  Edit: Or rather the other way round, a Hide All-Layer Mask:

                  var idMk = charIDToTypeID( "Mk  " );
                  var desc167 = new ActionDescriptor();
                  var idNw = charIDToTypeID( "Nw  " );
                  var idChnl = charIDToTypeID( "Chnl" );
                  desc167.putClass( idNw, idChnl );
                  var idAt = charIDToTypeID( "At  " );
                  var ref98 = new ActionReference();
                  var idChnl = charIDToTypeID( "Chnl" );
                  var idChnl = charIDToTypeID( "Chnl" );
                  var idMsk = charIDToTypeID( "Msk " );
                  ref98.putEnumerated( idChnl, idChnl, idMsk );
                  desc167.putReference( idAt, ref98 );
                  var idUsng = charIDToTypeID( "Usng" );
                  var idUsrM = charIDToTypeID( "UsrM" );
                  var idHdAl = charIDToTypeID( "HdAl" );
                  desc167.putEnumerated( idUsng, idUsrM, idHdAl );
                  executeAction( idMk, desc167, DialogModes.ALL );