Copy link to clipboard
Copied
I have over a hundred images (.tif or .TIF) that have clipped with a Path but the names are all different. Also, some have been activated to clipping paths. I need all the Paths/Clipping Paths to be named Path 1. I found an old javascript for this using ExtendScript Toolkit but it doesn't work. Any advice would be greatly appreciated.
var selFolder = Folder.selectDialog( 'Location of images to process...' );
var files = selFolder.getFiles ( /.TIF|.tif/i );// may need to edit for different formats
var newPathName = prompt ("Put your clipping path name that you want", 'Path 1', "Clipping Name")
for(var f = 0; f < files.length; f++ )
{
var doc = app.open( files[f] );
var numberOfPaths = doc.pathItems.length;
for( var p = 0; p < numberOfPaths; p++ )
{
if( doc.pathItems[ p ].kind == PathKind.CLIPPINGPATH && newPathName != doc.pathItems[ p ].name ) doc.pathItems[ p ].name = newPathName;
}
doc.close(SaveOptions.SAVECHANGES);
}
It is not a translation issue after all, some of the files had Sharing & Permissions issues so I changed them all to Read & Write. Then I ran two separate scripts because I don't know how to combine them into one. This is what worked:
This is script is for NORMALPATH paths:
var selFolder = Folder.selectDialog( 'Location of images to process...' );
var files = selFolder.getFiles ( /\.tif$/i );// may need to edit for different formats
var newPathName = prompt ("Put your clipping path name that y
...
Copy link to clipboard
Copied
Change your regular expression… The i flag is to ignore case and the dot needs escaping so…
var files = selFolder.getFiles ( /\.tif$/i )
Copy link to clipboard
Copied
I tried this but it still doesn't work, (Results: undefined). It opens several of the images and appears to do something but it doesn't actually change the Path names. It also stops before getting through all of them.
var selFolder = Folder.selectDialog( 'Location of images to process...' );
var files = selFolder.getFiles ( /\.tif$/i );// may need to edit for different formats
var newPathName = prompt ("Put your clipping path name that you want", 'Path 1', "Clipping Name")
for(var f = 0; f < files.length; f++ )
{
var doc = app.open( files[f] );
var numberOfPaths = doc.pathItems.length;
for( var p = 0; p < numberOfPaths; p++ )
{
if( doc.pathItems[ p ].kind == PathKind.CLIPPINGPATH && newPathName != doc.pathItems[ p ].name ) doc.pathItems[ p ].name = newPathName;
}
doc.close(SaveOptions.SAVECHANGES);
}
Copy link to clipboard
Copied
Wrong syntax.
Try something like this:
var numberOfPaths = activeDocument.pathItems;
if (numberOfPaths.length > 0) {
for (n =numberOfPaths.length-1; n>-1; n--) {
var a = numberOfPaths[n].kind;
if (a == "PathKind.CLIPPINGPATH" ) {
numberOfPaths[n].name = newPathName;
}
}
}
Have fun
Copy link to clipboard
Copied
This one gave me an error.
Error 1302: No such element
Line: 1
-> var numberOfPaths = activeDocument.pathItems;
Copy link to clipboard
Copied
should be var numberOfPaths = activeDocument.pathItems.length;
Copy link to clipboard
Copied
Hast du meinen Skriptschnipsel einmal an einer einzelnen Problemdatei getestet? Es sollte egal sein, wie der Pfad heißt. Nur wenn der Name bereits vorhanden ist, dann erscheint ein PS-eigener Dialog zum Umbennen. Aber vielleicht unterscheidet sich CS3 in diesem Fall von neueren Versionen.
Have you tested my script part with one single problem file? It should not matter how the path name is. Only if the name already exists, then a separate PS-own dialog appears to rename the path. But perhaps CS3 is different in this case in newer versions.
Copy link to clipboard
Copied
pixxxel schubser wrote:
It should not matter how the path name is. Only if the name already exists, then a separate PS-own dialog appears to rename the path.
That is true. I brought up the naming issuse because I thought it would be better to avoid that path name dialog. Otherwise it stops the script until dismissed so this task is not really fully automated.
Copy link to clipboard
Copied
Are you sure your tiff file contain a clipping path? Try adding a alert so you can see what kind of paths you have.
var selFolder = Folder.selectDialog( 'Location of images to process...' );
var files = selFolder.getFiles ( /\.tif$/i );// may need to edit for different formats
var newPathName = prompt ("Put your clipping path name that you want", 'Path 1', "Clipping Name")
for(var f = 0; f < files.length; f++ )
{
var doc = app.open( files[f] );
var numberOfPaths = doc.pathItems.length;
for( var p = 0; p < numberOfPaths; p++ )
{
if( doc.pathItems[ p ].kind == PathKind.CLIPPINGPATH && newPathName != doc.pathItems[ p ].name ) doc.pathItems[ p ].name = newPathName;
alert("PathItem = " + p + "\rKind = " + doc.pathItems[p].kind + "\rName = " + doc.pathItems[p].name);
}
doc.close(SaveOptions.SAVECHANGES);
}
Copy link to clipboard
Copied
When I ran this script I realized that the only two path names that were coming up were Path 1 or Pfad 1 (german for Path 1)! So it is a translation issue, not sure if there's an easy way to change the language on these files to English so the paths all match?
Copy link to clipboard
Copied
It is not a translation issue after all, some of the files had Sharing & Permissions issues so I changed them all to Read & Write. Then I ran two separate scripts because I don't know how to combine them into one. This is what worked:
This is script is for NORMALPATH paths:
var selFolder = Folder.selectDialog( 'Location of images to process...' );
var files = selFolder.getFiles ( /\.tif$/i );// may need to edit for different formats
var newPathName = prompt ("Put your clipping path name that you want", 'Path 1', "Path Name")
for(var f = 0; f < files.length; f++ )
{
var doc = app.open( files[f] );
var numberOfPaths = doc.pathItems.length;
for( var p = 0; p < numberOfPaths; p++ )
{
if( doc.pathItems[ p ].kind == PathKind.NORMALPATH && newPathName != doc.pathItems[ p ].name ) doc.pathItems[ p ].name = newPathName;
}
doc.close(SaveOptions.SAVECHANGES);
}
This is for CLIPPINGPATH paths:
var selFolder = Folder.selectDialog( 'Location of images to process...' );
var files = selFolder.getFiles ( /\.tif$/i );// may need to edit for different formats
var newPathName = prompt ("Put your clipping path name that you want", 'Path 1', "Clipping Name")
for(var f = 0; f < files.length; f++ )
{
var doc = app.open( files[f] );
var numberOfPaths = doc.pathItems.length;
for( var p = 0; p < numberOfPaths; p++ )
{
if( doc.pathItems[ p ].kind == PathKind.CLIPPINGPATH && newPathName != doc.pathItems[ p ].name ) doc.pathItems[ p ].name = newPathName;
}
doc.close(SaveOptions.SAVECHANGES);
}
I only had one file with two paths in it and a dialogue came up and I changed it to Path 2, no sweat.
Thanks everyone for all your help!
Copy link to clipboard
Copied
amazingman2000 wrote:
... I ran two separate scripts because I don't know how to combine them into one.
A simple way to combine the two scripts would be adding the if statement to the first script's paths loop.
for( var p = 0; p < numberOfPaths; p++ )
{
if( doc.pathItems[ p ].kind == PathKind.NORMALPATH && newPathName != doc.pathItems[ p ].name ) doc.pathItems[ p ].name = newPathName;
if( doc.pathItems[ p ].kind == PathKind.CLIPPINGPATH && newPathName != doc.pathItems[ p ].name ) doc.pathItems[ p ].name = newPathName;
}
Copy link to clipboard
Copied
@amazingman2000,
why do you need a clipping path which only named as one, but none is?
Copy link to clipboard
Copied
Hi amazingman2000,
I tried your script for clipping paths and it works great!
Except there are some files I cannot open after I run the script. The message I then see is "Cannot complete request because of a disk error". Do you know how this can happen?
Copy link to clipboard
Copied
Must be something with the filename, I'm not really sure. You're not running out of disk space right?
Copy link to clipboard
Copied
I don't know why it happened, but I ran the same script for all 16.000 files and it works fine now!
Copy link to clipboard
Copied
I see two problems.
One is this is only checking for Photoshop clipping path. If the document has a normal path that you are using as a clipping path but haven't set it up as a Photoshop clipping path the script will not do anything.
The second problem is Photoshop does not allow paths with the same name. The script doesn't check to see if there is already a path with newPathName before trying to rename.
However if all the files do have Photoshop clipping paths and that is the only path in the document I don't see why this isn't working for you.