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

Need a script for paths and clipping paths

Community Beginner ,
Jul 01, 2013 Jul 01, 2013

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);
}
TOPICS
Actions and scripting

Views

4.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

correct answers 1 Correct answer

Community Beginner , Jul 01, 2013 Jul 01, 2013

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
...

Votes

Translate

Translate
Adobe
Guru ,
Jul 01, 2013 Jul 01, 2013

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 )

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 ,
Jul 01, 2013 Jul 01, 2013

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

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 Expert ,
Jul 01, 2013 Jul 01, 2013

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

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 ,
Jul 01, 2013 Jul 01, 2013

Copy link to clipboard

Copied

This one gave me an error.

Error 1302: No such element

Line: 1

->  var numberOfPaths = activeDocument.pathItems;

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 Expert ,
Jul 01, 2013 Jul 01, 2013

Copy link to clipboard

Copied

should be var numberOfPaths = activeDocument.pathItems.length;

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 Expert ,
Jul 01, 2013 Jul 01, 2013

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.

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 ,
Jul 01, 2013 Jul 01, 2013

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.

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 Expert ,
Jul 01, 2013 Jul 01, 2013

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);
}
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 ,
Jul 01, 2013 Jul 01, 2013

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?

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 ,
Jul 01, 2013 Jul 01, 2013

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!

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 ,
Jul 01, 2013 Jul 01, 2013

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

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 Expert ,
Jul 01, 2013 Jul 01, 2013

Copy link to clipboard

Copied

@amazingman2000,

why do you need a clipping path which only named as one, but none is?

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
New Here ,
Feb 22, 2016 Feb 22, 2016

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?

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 ,
Mar 05, 2016 Mar 05, 2016

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?

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
New Here ,
Mar 06, 2016 Mar 06, 2016

Copy link to clipboard

Copied

LATEST

I don't know why it happened, but I ran the same script for all 16.000 files and it works fine now!

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 ,
Jul 01, 2013 Jul 01, 2013

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.

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