10 Replies Latest reply on Aug 9, 2017 6:15 PM by jindap

    Crop to Selection Action

    jindap Level 1

      Hello,

       

      Does anyone know how to "Crop to Selection" within an action so that each time the "Crop" step takes place, it crops to the specific selection of the document?  Currently this step works only by remembering the dimensions of the selection which were currently selected during the recording of the action.

       

      In a nutshell, I have hundreds of files which contain paths of the object within the document.  These objects are a range of different items so therefore, their paths and thus selections, will have varying dimensions.  I would like to crop each file down to the selection of said object quickly and save before running add'l actions.

       

      I would like the "Crop" step within the action to perform independently of the dimensions that were originally recorded.  again, my action only works on the file i recorded it on.  once i apply the same action to a different file, it crops with the previously recorded selection settings and not the current selection.

       

      any insight would be greatly appreciated.

       

      here are my steps already in place (Photoshop CC):

      1) duplicate background

      2) select backward layer

      3) make fill

      4) select forward layer

      5) set selection from "path1"

      6) Layer via copy

      7) set selection

      8) select brush

      9) crop (w/out delete crop pixels)

       

      JP

       

      Message was edited by: Jinda Phommavongsa

        • 1. Re: Crop to Selection Action
          macpawel Adobe Community Professional

          Maybe do somethink like this:

           

          1-8 - would be same

          9 - use Image>Crop command instead using Crop Tool

           

          it works fine in my example

           

          Pawel

          1 person found this helpful
          • 2. Re: Crop to Selection Action
            jindap Level 1

            Hi Macpawel,

             

            you're right that option does work, but i need retain the pixels outside the crop bounds because i'd like to run actions afterword which fit the image into set canvas size rules so each image, regardless of the selection dimensions, is placed into the same "pixel padding" specs.  i think using Image>Crop kills that by removing the pixels so that when i expand the canvas back out there are missing areas to my images.

            • 3. Re: Crop to Selection Action
              jindap Level 1

              To further clarify, here is a screenshot of the settings i'd like removed from the Crop step within my action.  is there any way that the Photoshop Crop tool can crop automatically to what the current selection is without remembering what was recorded?

              Screen Shot 2017-04-24 at 3.44.04 PM.png

              • 4. Re: Crop to Selection Action
                macpawel Adobe Community Professional

                OK, it's possible!

                Repeat 1-8 steps and then

                Go to Crop Tool (C) use Crop Settings Top-left corner and select Front Image option there

                Thats all - I hope

                 

                Pawel

                • 5. Re: Crop to Selection Action
                  jindap Level 1

                  Hi macpawel,

                   

                  that didn't work either, all that did was crop it back to the files original spec.  this one's got me stumped for sure.  i didn't have this issue when working with CS6.  this is a completely new issue since updating to CC.

                  Screen Shot 2017-04-24 at 4.27.38 PM.png

                  The only work around i've found so far is to add the dialog box to the Crop step, but that's defeating the point of my action if i have to manually go in there and move the crop around to fit each image.  would this be something that would need to be applescripted? like i mentioned, i've done this before in older versions no problem.

                  • 6. Re: Crop to Selection Action
                    jahaik Level 1

                    Any progress on this? I've made a script that does roughly what you're trying to do, but still have the issue of destructive cropping...otherwise it works great. has anyone figured out that issue?

                    • 7. Re: Crop to Selection Action
                      Chuck Uebele Adobe Community Professional & MVP

                      try adding this script to your action. Just make sure you have a selection for it to crop.

                       

                      var doc = activeDocument;
                      
                      try{
                          var bound = doc.selection.bounds
                          cropToSelection (bound[1], bound[0], bound[3], bound[2])
                      }
                      catch(e){}
                      
                      function cropToSelection(top, left, bottom, right){
                          var idCrop = charIDToTypeID( "Crop" );
                              var desc11 = new ActionDescriptor();
                              var idT = charIDToTypeID( "T   " );
                                  var desc12 = new ActionDescriptor();
                                  var idTop = charIDToTypeID( "Top " );
                                      var idPxl = charIDToTypeID( "#Pxl" );
                                  desc12.putUnitDouble( idTop, idPxl, top );
                                  var idLeft = charIDToTypeID( "Left" );
                                  var idPxl = charIDToTypeID( "#Pxl" );
                                  desc12.putUnitDouble( idLeft, idPxl,left );
                                  var idBtom = charIDToTypeID( "Btom" );
                                  var idPxl = charIDToTypeID( "#Pxl" );
                                  desc12.putUnitDouble( idBtom, idPxl, bottom );
                                  var idRght = charIDToTypeID( "Rght" );
                                  var idPxl = charIDToTypeID( "#Pxl" );
                                  desc12.putUnitDouble( idRght, idPxl, right );
                              var idRctn = charIDToTypeID( "Rctn" );
                              desc11.putObject( idT, idRctn, desc12 );
                              var idAngl = charIDToTypeID( "Angl" );
                              var idAng = charIDToTypeID( "#Ang" );
                              desc11.putUnitDouble( idAngl, idAng, 0.000000 );
                              var idDlt = charIDToTypeID( "Dlt " );
                              desc11.putBoolean( idDlt, false );
                              var idcropAspectRatioModeKey = stringIDToTypeID( "cropAspectRatioModeKey" );
                              var idcropAspectRatioModeClass = stringIDToTypeID( "cropAspectRatioModeClass" );
                              var idtargetSize = stringIDToTypeID( "targetSize" );
                              desc11.putEnumerated( idcropAspectRatioModeKey, idcropAspectRatioModeClass, idtargetSize );
                          executeAction( idCrop, desc11, DialogModes.NO );
                          }
                      
                      1 person found this helpful
                      • 8. Re: Crop to Selection Action
                        jahaik Level 1

                        hmm..this IS non-destructive, but when I tried this with a selection active it crops a 15x15 px square in the upper-left corner of the image but I can't seem to figure out why

                        • 9. Re: Crop to Selection Action
                          Chuck Uebele Adobe Community Professional & MVP

                          Are your document units set to pixels? If not, they need to be, of some lines of code need to be added to change the to pixels then back to whatever you were using.

                          1 person found this helpful
                          • 10. Re: Crop to Selection Action
                            jindap Level 1

                            Looks interesting.

                             

                            In the time I've been away I've been doing this work manually.

                             

                            Ill try the script. Wish me luck.