2 Replies Latest reply on May 25, 2015 7:30 AM by Bazsl

    Listener code to add layer mask fails...

    Bazsl Level 1

      Using Photoshop CC 2014 with all updates. The following script listener code was recorded when I clicked the Add Layer Mask button to add a mask to the active layer. When executeAction is called the script aborts with the following error dialog. Help! How can I add a layer mask to the active layer? Thanks.

       

      Error: General Photoshop error occurred. This functionality may not be available in this version of Photoshop. - The command "Make" is not currently available.

       

      function addLayerMask() {

        // Adds a layer mask to the active layer by clicking the

        // Add Layer Mask button.

        var idMk = charIDToTypeID( "Mk  " );

        var desc23 = new ActionDescriptor();

        var idNw = charIDToTypeID( "Nw  " );

        var idChnl = charIDToTypeID( "Chnl" );

        desc23.putClass( idNw, idChnl );

        var idAt = charIDToTypeID( "At  " );

        var ref20 = new ActionReference();

        var idChnl = charIDToTypeID( "Chnl" );

        var idChnl = charIDToTypeID( "Chnl" );

        var idMsk = charIDToTypeID( "Msk " );

        ref20.putEnumerated( idChnl, idChnl, idMsk );

        desc23.putReference( idAt, ref20 );

        var idUsng = charIDToTypeID( "Usng" );

        var idUsrM = charIDToTypeID( "UsrM" );

        var idRvlS = charIDToTypeID( "RvlS" );

        desc23.putEnumerated( idUsng, idUsrM, idRvlS );

        executeAction( idMk, desc23, DialogModes.NO );

      }

        • 1. Re: Listener code to add layer mask fails...
          JJMack Most Valuable Participant

          That code will work if you have an active selection.

           

          function addLayerMask() {

            // Adds a layer mask to the active layer by clicking the

            // Add Layer Mask button.

            var idMk = charIDToTypeID( "Mk  " );

            var desc23 = new ActionDescriptor();

            var idNw = charIDToTypeID( "Nw  " );

            var idChnl = charIDToTypeID( "Chnl" );

            desc23.putClass( idNw, idChnl );

            var idAt = charIDToTypeID( "At  " );

            var ref20 = new ActionReference();

            var idChnl = charIDToTypeID( "Chnl" );

            var idChnl = charIDToTypeID( "Chnl" );

            var idMsk = charIDToTypeID( "Msk " );

            ref20.putEnumerated( idChnl, idChnl, idMsk );

            desc23.putReference( idAt, ref20 );

            var idUsng = charIDToTypeID( "Usng" );

            var idUsrM = charIDToTypeID( "UsrM" );

            var idRvlS = charIDToTypeID( "RvlS" );

            desc23.putEnumerated( idUsng, idUsrM, idRvlS );      //reveal selection

            executeAction( idMk, desc23, DialogModes.NO );

          }

          app.activeDocument.selection.selectAll();

          addLayerMask();

           

           

          To add a layer mask without an active selection the is the scriptlistener code you would need

           

          function addLayerMask() {

          var idMk = charIDToTypeID( "Mk  " );

              var desc25 = new ActionDescriptor();

              var idNw = charIDToTypeID( "Nw  " );

              var idChnl = charIDToTypeID( "Chnl" );

              desc25.putClass( idNw, idChnl );

              var idAt = charIDToTypeID( "At  " );

                  var ref19 = new ActionReference();

                  var idChnl = charIDToTypeID( "Chnl" );

                  var idChnl = charIDToTypeID( "Chnl" );

                  var idMsk = charIDToTypeID( "Msk " );

                  ref19.putEnumerated( idChnl, idChnl, idMsk );

              desc25.putReference( idAt, ref19 );

              var idUsng = charIDToTypeID( "Usng" );

              var idUsrM = charIDToTypeID( "UsrM" );

              var idRvlA = charIDToTypeID( "RvlA" );

              desc25.putEnumerated( idUsng, idUsrM, idRvlA );  //reveal all

          executeAction( idMk, desc25, DialogModes.NO );

          }

          addLayerMask()

           

           

          Then again there is hide all

           

          var idMk = charIDToTypeID( "Mk  " );

              var desc33 = new ActionDescriptor();

              var idNw = charIDToTypeID( "Nw  " );

              var idChnl = charIDToTypeID( "Chnl" );

              desc33.putClass( idNw, idChnl );

              var idAt = charIDToTypeID( "At  " );

                  var ref27 = new ActionReference();

                  var idChnl = charIDToTypeID( "Chnl" );

                  var idChnl = charIDToTypeID( "Chnl" );

                  var idMsk = charIDToTypeID( "Msk " );

                  ref27.putEnumerated( idChnl, idChnl, idMsk );

              desc33.putReference( idAt, ref27 );

              var idUsng = charIDToTypeID( "Usng" );

              var idUsrM = charIDToTypeID( "UsrM" );

              var idHdAl = charIDToTypeID( "HdAl" );

              desc33.putEnumerated( idUsng, idUsrM, idHdAl );     //Hide all

          executeAction( idMk, desc33, DialogModes.NO );

          • 2. Re: Listener code to add layer mask fails...
            Bazsl Level 1

            Thanks for the very complete answer. My problem was that the selection was not being created, which I did not discover until I single stepped through the code and watched what was happening in Photoshop, and, of course, the error message provided no clue as to the real problem.