• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
1

Transfering clipping paths from one folder of files to another?

Community Beginner ,
Sep 14, 2010 Sep 14, 2010

Copy link to clipboard

Copied

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

TOPICS
Actions and scripting

Views

2.7K

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Adobe
Community Expert ,
Sep 14, 2010 Sep 14, 2010

Copy link to clipboard

Copied

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.

JJMack

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Sep 14, 2010 Sep 14, 2010

Copy link to clipboard

Copied

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guide ,
Sep 14, 2010 Sep 14, 2010

Copy link to clipboard

Copied

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=db5d147517a7b1be26bf2684006b85bb#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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guru ,
Sep 14, 2010 Sep 14, 2010

Copy link to clipboard

Copied

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Sep 15, 2010 Sep 15, 2010

Copy link to clipboard

Copied

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

Regards, Tim

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guide ,
Sep 15, 2010 Sep 15, 2010

Copy link to clipboard

Copied

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);           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);           //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.pathPoints.length; i++) {                     pArray = new PathPointInfo;          pArray.kind = pathObj.subPathItems.pathPoints.kind;          pArray.anchor = pathObj.subPathItems.pathPoints.anchor;          pArray.leftDirection = pathObj.subPathItems.pathPoints.leftDirection;          pArray.rightDirection = pathObj.subPathItems.pathPoints.rightDirection;                }           pathArray[pathArray.length] = new Array();           pathArray[pathArray.length-1] = new SubPathInfo();           pathArray[pathArray.length-1].operation = pathObj.subPathItems.operation;           pathArray[pathArray.length-1].closed = pathObj.subPathItems.closed;           pathArray[pathArray.length-1].entireSubPath = pArray;      }      return pathArray; }

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Sep 15, 2010 Sep 15, 2010

Copy link to clipboard

Copied

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Sep 15, 2010 Sep 15, 2010

Copy link to clipboard

Copied

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guide ,
Sep 15, 2010 Sep 15, 2010

Copy link to clipboard

Copied

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);           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);           //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.pathPoints.length; i++) {                     pArray = new PathPointInfo;          pArray.kind = pathObj.subPathItems.pathPoints.kind;          pArray.anchor = pathObj.subPathItems.pathPoints.anchor;          pArray.leftDirection = pathObj.subPathItems.pathPoints.leftDirection;          pArray.rightDirection = pathObj.subPathItems.pathPoints.rightDirection;                }           pathArray[pathArray.length] = new Array();           pathArray[pathArray.length-1] = new SubPathInfo();           pathArray[pathArray.length-1].operation = pathObj.subPathItems.operation;           pathArray[pathArray.length-1].closed = pathObj.subPathItems.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…

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guru ,
Sep 15, 2010 Sep 15, 2010

Copy link to clipboard

Copied

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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guide ,
Sep 15, 2010 Sep 15, 2010

Copy link to clipboard

Copied

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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guru ,
Sep 15, 2010 Sep 15, 2010

Copy link to clipboard

Copied

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;
     }
};

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
Dec 02, 2010 Dec 02, 2010

Copy link to clipboard

Copied

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Dec 02, 2010 Dec 02, 2010

Copy link to clipboard

Copied

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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
Dec 02, 2010 Dec 02, 2010

Copy link to clipboard

Copied

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Dec 03, 2010 Dec 03, 2010

Copy link to clipboard

Copied

Just jpegs


Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
Dec 03, 2010 Dec 03, 2010

Copy link to clipboard

Copied

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
Dec 03, 2010 Dec 03, 2010

Copy link to clipboard

Copied

LATEST

Hi Mark

thanks! a very helpful script.

regards

j

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines