18 Replies Latest reply on Dec 3, 2010 1:05 PM by - JM -

    Transfering clipping paths from one folder of files to another?

    talltim1 Level 1

      Is there a clever scripty way of bringing a clipping path from one photoshop file to another photoshop file (pixel perfect, they are the same image).... preferbly maybe having a folder full of doner files that have the clipping paths that a script gets their clipping paths and puts them onto the photoshop files in the second folder? (the two folders will have files with same file names)

       

      Regards, Tim

        • 1. Re: Transfering clipping paths from one folder of files to another?
          JJMack Most Valuable Participant

          Will the files be the same size and resolution? May have to be.  You could try using the ScriptListener plug-in to get some ideas open the first file then open the second file and drag the path from the second file into the first file then close the second file exit Photoshop and look at the code generated. You may be able to create a function to open the second file by name and location  drag and drop the path by path name into the previous document and close the newly open document.

          • 2. Re: Transfering clipping paths from one folder of files to another?
            talltim1 Level 1

            Yes everything about the corresponding files in each folder are the same except one folder has colour corrected files and we need the paths to go on those. I'll look into the scriptlistener plug-in. But if anyone knows any professional photoshop script writer that we can hire that can do this script fairly quick, please let me know.

             

            Regards, Tim

            • 3. Re: Transfering clipping paths from one folder of files to another?
              Muppet Mark-QAl63s Level 4

              Take a look at this thread over at www.ps-scripts.com there was a discussion about scripting path items not so long ago.

               

              http://www.ps-scripts.com/bb/viewtopic.php?f=9&t=3368&p=15155&hilit=entire+path&sid=db5d14 7517a7b1be26bf2684006b85bb#p15155

               

              From this it should be possible to create a script that does just what you want. In fact I've been meaning to do this myself for a little while but just not gotten around to it. We send files out over the net to be clipped out these are compressed using JPEG so copying the paths back to our originals is best. I've seen a few requests for this just lately so I think this is becoming a more common workflow.

              • 4. Re: Transfering clipping paths from one folder of files to another?
                Michael L Hale Level 5

                talltim, do you still need help with this? I replied with a couple of questions to your post at PS-Scripts.

                • 5. Re: Transfering clipping paths from one folder of files to another?
                  talltim1 Level 1

                  Hi Michael, thanks for your reply. We use Photoshop CS4 and they are clipping paths.

                   

                  Regards, Tim

                  • 6. Re: Transfering clipping paths from one folder of files to another?
                    Muppet Mark-QAl63s Level 4

                    This may or may not be close to what you need… Its still a little presumptuous at the moment in the fact that its only looking in to the first path of the JPEG file. But you may only have the one? I never did find a way to get a clipping paths flatness? So I hardcode the settings I wanted. I still could do with one for multi-paths, but I will look in to that another time. I'd still wait and see what Mike comes up with though…

                     

                    #target photoshop
                    
                    function main() {
                         app.bringToFront();
                         var userDD = app.displayDialogs;
                         var defaultFolder = new Folder('~/Desktop');
                         var jpegFolder = Folder.selectDialog('Please select your folder of JPEGs…', defaultFolder);
                         if (jpegFolder != null) {
                              var jpegList = jpegFolder.getFiles(/\.(jpg|jpeg)$/i);
                         }
                         if (jpegList.length == 0) {
                              alert('There are NO "JPEG" files in this Folder…');
                              return;
                         }
                         var tiffFolder = Folder.selectDialog('Please select your folder of TIFFs…', defaultFolder);
                         if (tiffFolder != null) {
                              var tiffList = tiffFolder.getFiles(/\.(tif|tiff)$/i);
                         }
                         if (tiffList.length == 0) {
                              alert('There are NO "TIFF" files in this Folder…'); 
                              return;
                         }
                         if (jpegList.length != tiffList.length) {
                              alert('The number of expected files is "NOT" equal?');
                              return;
                         }
                         for (var i = 0; i < jpegList.length; i++) {
                              open(jpegList[i]);
                              if (app.activeDocument.resolution != 72) {
                                   app.activeDocument.resizeImage(undefined, undefined, 72, ResampleMethod.NONE);
                              }
                              if (app.activeDocument.pathItems.length > 0) {
                                   var pathName = app.activeDocument.pathItems[0].name;
                                   var pathKind = app.activeDocument.pathItems[0].kind;
                                   //var pathFlat = app.activeDocument.pathItems[0].flattness; // How to get this???
                                   var pathInfo = extractSubPathInfo(app.activeDocument.pathItems[0]);
                                   app.activeDocument.close(SaveOptions.DONOTSAVECHANGES);
                              }else{
                                   app.activeDocument.close(SaveOptions.DONOTSAVECHANGES);
                                   continue;
                              }
                              open(tiffList[i]);
                              //app.activeDocument.pathItems.removeAll(); // If you have any existing paths in TIFF?
                              if (app.activeDocument.resolution != 72) {
                                   var origRes = app.activeDocument.resolution;
                                   app.activeDocument.resizeImage(undefined, undefined, 72, ResampleMethod.NONE);
                                   app.activeDocument.pathItems.add(pathName, pathInfo);
                                   if (pathKind == PathKind.CLIPPINGPATH) app.activeDocument.pathItems[0].makeClippingPath(0.5);
                                   app.activeDocument.resizeImage(undefined, undefined, origRes, ResampleMethod.NONE);
                              }else{
                                   app.activeDocument.pathItems.add(pathName, pathInfo);
                              }
                              app.activeDocument.close(SaveOptions.SAVECHANGES);
                         }
                         app.displayDialogs = userDD;
                    }
                    
                    main();
                    
                    ////////////////////////////////////////////////////////////////
                    /*
                    Function by Mike Hale & Christoph Pfaffenbichler @ ps-script.com
                    */
                    ////////////////////////////////////////////////////////////////
                    
                    function extractSubPathInfo(pathObj){
                         var pathArray = new Array();
                         var pl = pathObj.subPathItems.length;
                         for(var s = 0; s < pl; s++) {
                              var pArray = new Array();
                                   for(var i = 0; i < pathObj.subPathItems[s].pathPoints.length; i++) {
                                        pArray[i] = new PathPointInfo;
                             pArray[i].kind = pathObj.subPathItems[s].pathPoints[i].kind;
                             pArray[i].anchor = pathObj.subPathItems[s].pathPoints[i].anchor;
                             pArray[i].leftDirection = pathObj.subPathItems[s].pathPoints[i].leftDirection;
                             pArray[i].rightDirection = pathObj.subPathItems[s].pathPoints[i].rightDirection;
                                   }
                              pathArray[pathArray.length] = new Array();
                              pathArray[pathArray.length-1] = new SubPathInfo();
                              pathArray[pathArray.length-1].operation = pathObj.subPathItems[s].operation;
                              pathArray[pathArray.length-1].closed = pathObj.subPathItems[s].closed;
                              pathArray[pathArray.length-1].entireSubPath = pArray;
                         }
                         return pathArray;
                    }
                    

                    • 7. Re: Transfering clipping paths from one folder of files to another?
                      talltim1 Level 1

                      Hi Mark, thanks very much I will give this a test.

                      All our files are jpeg and there is only one clipping path on the files that have clipping paths

                      • 8. Re: Transfering clipping paths from one folder of files to another?
                        talltim1 Level 1

                        Hi Mark, nearly worked for us. Just two issues.

                         

                        Both folders will be full of jpegs. No tiffs, which the script looks for in the second folder.

                         

                        The second thing is, (I used some tiffs as a test in principle), and while it put the path on the tiffs, they were just normal paths... not clipping as they were on the jpegs

                         

                        Cheers, Tim

                        • 9. Re: Transfering clipping paths from one folder of files to another?
                          Muppet Mark-QAl63s Level 4

                          Tim, Im at work at the moment changing the syntax to deal with 2 folders of JPEGs should be simple enough. The syntax is already there it would just need a variable other than the first list for the second. I will go check again on the clipping issue which I thought I tested for this last night?

                           

                          #target photoshop
                          
                          function main() {
                               app.bringToFront();
                               var userDD = app.displayDialogs;
                               var defaultFolder = new Folder('~/Desktop');
                               var sourceFolder = Folder.selectDialog('Please select your folder of JPEGs with Paths…', defaultFolder);
                               if (sourceFolder != null) {
                                    var sourceList = sourceFolder.getFiles(/\.(jpg|jpeg)$/i);
                               }
                               if (sourceList.length == 0) {
                                    alert('There are NO "JPEG" files in this Folder…');
                                    return;
                               }
                               var destFolder = Folder.selectDialog('Please select your folder of JPEGs without Paths…', defaultFolder);
                               if (destFolder != null) {
                                    var destList = destFolder.getFiles(/\.(jpg|jpeg)$/i);
                               }
                               if (destList.length == 0) {
                                    alert('There are NO "JPEG" files in this Folder…'); 
                                    return;
                               }
                               if (sourceList.length != destList.length) {
                                    alert('The number of expected files is "NOT" equal?');
                                    return;
                               }
                               for (var i = 0; i < sourceList.length; i++) {
                                    open(sourceList[i]);
                                    if (app.activeDocument.resolution != 72) {
                                         app.activeDocument.resizeImage(undefined, undefined, 72, ResampleMethod.NONE);
                                    }
                                    if (app.activeDocument.pathItems.length > 0) {
                                         var pathName = app.activeDocument.pathItems[0].name;
                                         var pathKind = app.activeDocument.pathItems[0].kind;
                                         var pathInfo = extractSubPathInfo(app.activeDocument.pathItems[0]);
                                         app.activeDocument.close(SaveOptions.DONOTSAVECHANGES);
                                    }else{
                                         app.activeDocument.close(SaveOptions.DONOTSAVECHANGES);
                                         continue;
                                    }
                                    open(destList[i]);
                                    //app.activeDocument.pathItems.removeAll(); // If you have any existing paths in TIFF?
                                    if (app.activeDocument.resolution != 72) {
                                         var origRes = app.activeDocument.resolution;
                                         app.activeDocument.resizeImage(undefined, undefined, 72, ResampleMethod.NONE);
                                         app.activeDocument.pathItems.add(pathName, pathInfo);
                                         if (pathKind == PathKind.CLIPPINGPATH) {
                                              app.activeDocument.pathItems[0].makeClippingPath(0.5);
                                         }
                                         app.activeDocument.resizeImage(undefined, undefined, origRes, ResampleMethod.NONE);
                                    }else{
                                         app.activeDocument.pathItems.add(pathName, pathInfo);
                                    }
                                    app.activeDocument.close(SaveOptions.SAVECHANGES);
                               }
                               app.displayDialogs = userDD;
                          }
                          
                          main();
                          
                          ////////////////////////////////////////////////////////////////
                          /*
                          Function by Mike Hale & Christoph Pfaffenbichler @ ps-script.com
                          */
                          ////////////////////////////////////////////////////////////////
                          
                          function extractSubPathInfo(pathObj){
                               var pathArray = new Array();
                               var pl = pathObj.subPathItems.length;
                               for(var s = 0; s < pl; s++) {
                                    var pArray = new Array();
                                         for(var i = 0; i < pathObj.subPathItems[s].pathPoints.length; i++) {
                                              pArray[i] = new PathPointInfo;
                                   pArray[i].kind = pathObj.subPathItems[s].pathPoints[i].kind;
                                   pArray[i].anchor = pathObj.subPathItems[s].pathPoints[i].anchor;
                                   pArray[i].leftDirection = pathObj.subPathItems[s].pathPoints[i].leftDirection;
                                   pArray[i].rightDirection = pathObj.subPathItems[s].pathPoints[i].rightDirection;
                                         }
                                    pathArray[pathArray.length] = new Array();
                                    pathArray[pathArray.length-1] = new SubPathInfo();
                                    pathArray[pathArray.length-1].operation = pathObj.subPathItems[s].operation;
                                    pathArray[pathArray.length-1].closed = pathObj.subPathItems[s].closed;
                                    pathArray[pathArray.length-1].entireSubPath = pArray;
                               }
                               return pathArray;
                          }
                          

                           

                          Give this a try I think it only had a typo change or two… Plus I must have removed a pair of brackets… Idiot…

                          1 person found this helpful
                          • 10. Re: Transfering clipping paths from one folder of files to another?
                            Michael L Hale Level 5

                            Mark, because the copied path will be the activePath I would use Action Manager to make the copied path a clipping path( function below )

                             

                            To check if a document has a clipping path and find the index of the path if there is one use the function below.

                             

                            function makeClippingPath() {
                                 try{
                                      var desc = new ActionDescriptor( flatness );
                                           var ref = new ActionReference();
                                           ref.putProperty( charIDToTypeID('Path'), charIDToTypeID('ClPt') );
                                      desc.putReference( charIDToTypeID('null'), ref );
                                           var pathDesc = new ActionDescriptor();
                                                var pathRef = new ActionReference();
                                                pathRef.putEnumerated( charIDToTypeID('Path'), charIDToTypeID('Ordn'), charIDToTypeID('Trgt') );
                                           pathDesc.putReference( charIDToTypeID('Path'), pathRef );
                                           pathDesc.putDouble( charIDToTypeID('Fltn'), flatness );
                                      desc.putObject( charIDToTypeID('T   '), charIDToTypeID('ClpP'), pathDesc );
                                      executeAction( charIDToTypeID('setd'), desc, DialogModes.NO );
                                      return true;
                                 }catch(e){}
                            };
                            function hasClippingPathIndex(){// returns -1 if no clipping path     
                                 var ref = new ActionReference();
                                 ref.putEnumerated( charIDToTypeID("Dcmn"), charIDToTypeID("Ordn"), charIDToTypeID("Trgt") ); 
                                 var desc = executeActionGet(ref);
                                 return desc.getObjectValue(stringIDToTypeID('clippingPathInfo')).getInteger(stringIDToTypeID('clippingPathIndex'));
                            };
                            

                             

                            If you don't have time to put it all together for Tim let me know.

                             

                            EDIT:. Mark posted while I was typing this. Mark the copied path will not be a clipping path by default because the script creates a new path from the other path's info. You will need to either use the DOM or AM to make it a clipping path.

                            1 person found this helpful
                            • 11. Re: Transfering clipping paths from one folder of files to another?
                              Muppet Mark-QAl63s Level 4

                              Mike, I made variables to both the paths name and kind outside of your function. I think the reason for it NOT making the clipping path was down to a pair of missing brackets after my if statement? (around line 47 in the first post). I see from your AM code that you are able to get the flatness that I have not been able to do before… Im used to looking for a clipping path by just looping in pathItems using the DOM but will give that a try out. Thanks.

                              • 12. Re: Transfering clipping paths from one folder of files to another?
                                Michael L Hale Level 5

                                Mark, I just noticed that you wanted a way to get the clipping path's flatness. The scripting guide says that the flatness range is 0.2 - 100. So does the warning if you try to enter 0 in the GUI Clipping Path dialog. But if you leave flatness blank in the dialog, Photoshop creates a clipping path with a flatness of 0. ( at least CS4 does )

                                 

                                function getClippingPathFlatness(){// returns -1 if there is no clipping path   
                                     var ref = new ActionReference();
                                     ref.putEnumerated( charIDToTypeID("Dcmn"), charIDToTypeID("Ordn"), charIDToTypeID("Trgt") ); 
                                     var desc = executeActionGet(ref);
                                      if( desc.getObjectValue(stringIDToTypeID('clippingPathInfo')).getInteger(stringIDToTypeID('clippingPathIndex')) != -1  ){
                                          return (desc.getObjectValue(stringIDToTypeID('clippingPathInfo')).getInteger(stringIDToTypeID('clippingPathFlatness'))/65536);
                                      }else{
                                           return -1;
                                     }
                                };
                                
                                • 13. Re: Transfering clipping paths from one folder of files to another?
                                  - JM - Level 3

                                  I just stumbled onto this thread. Nice script, worked well for me, I had a similar need. Thanks to all involved!

                                   

                                  did this script evolve any further with other functions or file formats?

                                   

                                  thanks

                                   

                                  j

                                  • 14. Re: Transfering clipping paths from one folder of files to another?
                                    talltim1 Level 1

                                    Yes, the script worked well for us but for some reason a small number of files had the wrong clipping paths put on them. We had the script running on several computers and it was some time before we discovered this, so not sure how it happened. We identified the files and re-ran the script and it was fine in the end. Just letting you know to have a QA procedure for the files.

                                    • 15. Re: Transfering clipping paths from one folder of files to another?
                                      - JM - Level 3

                                      Hi  talltim1

                                       

                                      Glad to hear it's working for you, I was only able to give it a brief test today. Hopefully I'll have time tomorrow to give it another try. Did you stick with jpgs for both folders or did you figure out a method for using PSD files?

                                       

                                      j

                                      • 17. Re: Transfering clipping paths from one folder of files to another?
                                        - JM - Level 3

                                        Hi Tim

                                         

                                        I ran into an unusual issue, jpgs saved directly out of ACR required me to click on the save options, whereas jpgs saved out of PS saved without any interaction. Just opening the ACR saved jpgs and resaving would then allow the script to run successfully. No change in any of the file parameters, just resaving with the same name and settings.


                                        Since it wasn't my preference to use jpgs as the file to copy the paths to, I tried TIFS and PSD files and happily both worked fine. The PSD files worked even if there were layers present.

                                         

                                        It only required changing: line 17   

                                         

                                                  var destList = destFolder.getFiles(/\.(psd)$/i);

                                         

                                        or

                                         

                                                  var destList = destFolder.getFiles(/\.(tif)$/i);

                                         

                                        I really don't have a clue as to what I am doing with scripting so it could be entirely wrong, but it worked, and that's all I need.

                                         

                                        j

                                        • 18. Re: Transfering clipping paths from one folder of files to another?
                                          - JM - Level 3

                                          Hi Mark

                                           

                                          thanks! a very helpful script.

                                           

                                          regards

                                           

                                          j