6 Replies Latest reply on Feb 28, 2014 10:50 AM by mkeatley17

    Scripting New Crop Tool

    mkeatley17 Level 1

      I'm having a difficult time scripting the new crop tool.  Despite specifying the initial 4 corners, it quickly expands to fill the entire document before anyone can use it.  Any suggestiong on how to fix this??

       

      Here's what I want:

       

      Screen Shot 2014-02-26 at 2.33.56 PM.jpg

       

      Here's what I get:

       

      Screen Shot 2014-02-26 at 2.33.48 PM.jpg

       

      Hee's my code:

       

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

      var idCrop = charIDToTypeID( "Crop" );

          var desc142 = new ActionDescriptor();

          var idT = charIDToTypeID( "T   " );

              var desc143 = new ActionDescriptor();

              var idTop = charIDToTypeID( "Top " );

              var idPxl = charIDToTypeID( "#Pxl" );

              desc143.putUnitDouble( idTop, idPxl, 100 );

              var idLeft = charIDToTypeID( "Left" );

              var idPxl = charIDToTypeID( "#Pxl" );

              desc143.putUnitDouble( idLeft, idPxl, 100 );

              var idBtom = charIDToTypeID( "Btom" );

              var idPxl = charIDToTypeID( "#Pxl" );

              desc143.putUnitDouble( idBtom, idPxl, 200 );

              var idRght = charIDToTypeID( "Rght" );

              var idPxl = charIDToTypeID( "#Pxl" );

              desc143.putUnitDouble( idRght, idPxl, 200 );

          var idRctn = charIDToTypeID( "Rctn" );

          desc142.putObject( idT, idRctn, desc143 );

          var idAngl = charIDToTypeID( "Angl" );

          var idAng = charIDToTypeID( "#Ang" );

          desc142.putUnitDouble( idAngl, idAng, 0.000000 );

          var idDlt = charIDToTypeID( "Dlt " );

          desc142.putBoolean( idDlt, true );

          var idcropAspectRatioModeKey = stringIDToTypeID( "cropAspectRatioModeKey" );

          var idcropAspectRatioModeClass = stringIDToTypeID( "cropAspectRatioModeClass" );

          var idunconstrained = stringIDToTypeID( "unconstrained" );

          desc142.putEnumerated( idcropAspectRatioModeKey, idcropAspectRatioModeClass, idunconstrained );

      executeAction( idCrop, desc142, DialogModes.NO );

        • 1. Re: Scripting New Crop Tool
          Chuck Uebele Adobe Community Professional & MVP

          I think you recorded the crop with the wrong type of crop.  It looks like you used a ratio crop rather than a specific width, height, res crop.  Here's what I got using scriptListener.  Notice the difference in the last few lines.

           

          var docRef = activeDocument

          var idCrop = charIDToTypeID( "Crop" );

              var desc8 = new ActionDescriptor();

              var idT = charIDToTypeID( "T   " );

                  var desc9 = new ActionDescriptor();

                  var idTop = charIDToTypeID( "Top " );

                  var idPxl = charIDToTypeID( "#Pxl" );

                  desc9.putUnitDouble( idTop, idPxl, 108.000000 );

                  var idLeft = charIDToTypeID( "Left" );

                  var idPxl = charIDToTypeID( "#Pxl" );

                  desc9.putUnitDouble( idLeft, idPxl, 186.000000 );

                  var idBtom = charIDToTypeID( "Btom" );

                  var idPxl = charIDToTypeID( "#Pxl" );

                  desc9.putUnitDouble( idBtom, idPxl, 374.000000 );

                  var idRght = charIDToTypeID( "Rght" );

                  var idPxl = charIDToTypeID( "#Pxl" );

                  desc9.putUnitDouble( idRght, idPxl, 633.000000 );

              var idRctn = charIDToTypeID( "Rctn" );

              desc8.putObject( idT, idRctn, desc9 );

              var idAngl = charIDToTypeID( "Angl" );

              var idAng = charIDToTypeID( "#Ang" );

              desc8.putUnitDouble( idAngl, idAng, 0.000000 );

              var idDlt = charIDToTypeID( "Dlt " );

              desc8.putBoolean( idDlt, true );

              var idcropAspectRatioModeKey = stringIDToTypeID( "cropAspectRatioModeKey" );

              var idcropAspectRatioModeClass = stringIDToTypeID( "cropAspectRatioModeClass" );

              var idtargetSize = stringIDToTypeID( "targetSize" );

              desc8.putEnumerated( idcropAspectRatioModeKey, idcropAspectRatioModeClass, idtargetSize );

          executeAction( idCrop, desc8, DialogModes.ALL);

           

          app.displayDialogs = DialogModes.NO;

          • 2. Re: Scripting New Crop Tool
            mkeatley17 Level 1

            Thank you.  However I'm getting an error when I run that:

             

            Screen Shot 2014-02-26 at 4.14.41 PM.jpg

             

            I'm not seeing which setting you are saying to choose:

             

            Screen Shot 2014-02-26 at 4.17.49 PM.jpg

            • 3. Re: Scripting New Crop Tool
              Chuck Uebele Adobe Community Professional & MVP

              Looks like you're using CS6, and I was using CC.  It works with the setting shown below, but CS6 doesn't have that feature.  Adobe did a lot of improvements with the crop tool between CS6 and CC, this must have been one of them.

              crop2.jpg

              • 4. Re: Scripting New Crop Tool
                mkeatley17 Level 1

                ok thanks.  I'm sorry I should have clairifed CS6.  I thought "new crop tool" made sense to everyone!

                • 5. Re: Scripting New Crop Tool
                  JJMack Most Valuable Participant

                  Why are you using Scriptlistener Action Manager code and not Adobe DOM. crop(bounds) is more readable

                   

                  app.activeDocument.crop(bounds[, angle][, width][, height])

                  array of 4 UnitValue

                  number

                  UnitValue

                  UnitValue

                  Crops the document. The bounds parameter is an array of four coordinates for the region remaining after cropping,[left, top, right, bottom].

                  • 6. Re: Scripting New Crop Tool
                    mkeatley17 Level 1

                    I was using SL because at that point in the program the user needs to interact with the crop and adjust it before hitting enter.  I just wanted the crop box to begin at an exact location to give a sense of proportion to the user. 

                     

                    Thanks for the help though!