Skip to main content
Participating Frequently
May 30, 2020
Answered

Script to copy pen path name to layer names

  • May 30, 2020
  • 2 replies
  • 2141 views

Usually I create several pen paths (around 10) to isolate several areas of an image.  In my workflow I create several layer groups, each one with the same name as the corresponding path.  I'm looking for a script to create different groups, one group for each of the paths.  I need that each group keep the same name as the paths.  Each group will end up with a different name.

Thanks for your help.

This topic has been closed for replies.
Correct answer c.pfaffenbichler
// 2020, use it at your own risk;
if (app.documents.length > 0) {
var thePaths = collectPaths ();
var ref4 = new ActionReference();
ref4.putProperty(stringIDToTypeID("property"), stringIDToTypeID("numberOfLayers"));
ref4.putEnumerated( charIDToTypeID("Dcmn"), charIDToTypeID("Ordn"), charIDToTypeID("Trgt") ); 
var docDesc = executeActionGet(ref4);
var theNumberOfLayers = docDesc.getInteger(stringIDToTypeID("numberOfLayers"));
// create groups;
for (var m = 0; m < thePaths.length; m++) {
var theName = thePaths[m][0];
// =======================================================
var idname = stringIDToTypeID( "name" );
    var desc2 = new ActionDescriptor();
        var ref1 = new ActionReference();
        ref1.putClass( stringIDToTypeID( "layerSection" ) );
    desc2.putReference( stringIDToTypeID( "null" ), ref1 );
        var desc3 = new ActionDescriptor();
        desc3.putString( idname, theName );
    desc2.putObject( stringIDToTypeID( "using" ), stringIDToTypeID( "layerSection" ), desc3 );
    desc2.putInteger( stringIDToTypeID( "layerSectionStart" ), theNumberOfLayers++ );
    desc2.putInteger( stringIDToTypeID( "layerSectionEnd" ), theNumberOfLayers++ );
    desc2.putString( idname, theName );
executeAction( stringIDToTypeID( "make" ), desc2, DialogModes.NO );
}
};
////// collect layers //////
function collectPaths () {
// the file;
var myDocument = app.activeDocument;
// get number of paths;
var ref = new ActionReference();
ref.putProperty(stringIDToTypeID("property"), stringIDToTypeID("numberOfPaths"));
ref.putEnumerated( charIDToTypeID("Dcmn"), charIDToTypeID("Ordn"), charIDToTypeID("Trgt") ); 
var applicationDesc = executeActionGet(ref);
var theNumber = applicationDesc.getInteger(stringIDToTypeID("numberOfPaths"));
// process the paths;
var thePaths = new Array;
for (var m = 0; m <= theNumber; m++) {
try {
var ref = new ActionReference();
ref.putIndex( stringIDToTypeID( "path" ), m);
var pathDesc = executeActionGet(ref);
var theName = pathDesc.getString(stringIDToTypeID('pathName'));
var theID = pathDesc.getInteger(stringIDToTypeID('ID'));
thePaths.push([theName, theID])
}
catch (e) {};
};
return thePaths
};

2 replies

c.pfaffenbichler
Community Expert
Community Expert
May 30, 2020

»I need that each group keep the same name as the paths.  Each group will end with a different name.«

What does that mean? Should the Groups have the same name as the Paths or …? What »end« are you referring to? 

 

The task does not seem particularly difficukt in principle; how familiar are you with JavaScript and Photoshop’s DOM and AM-code? 

Participating Frequently
May 30, 2020

Thanks for your attention.

 Should the Groups have the same name as the Paths .  Answer: yes.

 

What »end« are you referring to? 

A: "end up"  just made the edit to the original post.

 

how familiar are you with JavaScript and Photoshop’s DOM and AM-code? 

A: Zero, nada.  Know nothing about scripting and programming.

c.pfaffenbichler
Community Expert
c.pfaffenbichlerCommunity ExpertCorrect answer
Community Expert
May 31, 2020
// 2020, use it at your own risk;
if (app.documents.length > 0) {
var thePaths = collectPaths ();
var ref4 = new ActionReference();
ref4.putProperty(stringIDToTypeID("property"), stringIDToTypeID("numberOfLayers"));
ref4.putEnumerated( charIDToTypeID("Dcmn"), charIDToTypeID("Ordn"), charIDToTypeID("Trgt") ); 
var docDesc = executeActionGet(ref4);
var theNumberOfLayers = docDesc.getInteger(stringIDToTypeID("numberOfLayers"));
// create groups;
for (var m = 0; m < thePaths.length; m++) {
var theName = thePaths[m][0];
// =======================================================
var idname = stringIDToTypeID( "name" );
    var desc2 = new ActionDescriptor();
        var ref1 = new ActionReference();
        ref1.putClass( stringIDToTypeID( "layerSection" ) );
    desc2.putReference( stringIDToTypeID( "null" ), ref1 );
        var desc3 = new ActionDescriptor();
        desc3.putString( idname, theName );
    desc2.putObject( stringIDToTypeID( "using" ), stringIDToTypeID( "layerSection" ), desc3 );
    desc2.putInteger( stringIDToTypeID( "layerSectionStart" ), theNumberOfLayers++ );
    desc2.putInteger( stringIDToTypeID( "layerSectionEnd" ), theNumberOfLayers++ );
    desc2.putString( idname, theName );
executeAction( stringIDToTypeID( "make" ), desc2, DialogModes.NO );
}
};
////// collect layers //////
function collectPaths () {
// the file;
var myDocument = app.activeDocument;
// get number of paths;
var ref = new ActionReference();
ref.putProperty(stringIDToTypeID("property"), stringIDToTypeID("numberOfPaths"));
ref.putEnumerated( charIDToTypeID("Dcmn"), charIDToTypeID("Ordn"), charIDToTypeID("Trgt") ); 
var applicationDesc = executeActionGet(ref);
var theNumber = applicationDesc.getInteger(stringIDToTypeID("numberOfPaths"));
// process the paths;
var thePaths = new Array;
for (var m = 0; m <= theNumber; m++) {
try {
var ref = new ActionReference();
ref.putIndex( stringIDToTypeID( "path" ), m);
var pathDesc = executeActionGet(ref);
var theName = pathDesc.getString(stringIDToTypeID('pathName'));
var theID = pathDesc.getInteger(stringIDToTypeID('ID'));
thePaths.push([theName, theID])
}
catch (e) {};
};
return thePaths
};
JJMack
Community Expert
Community Expert
May 30, 2020

You are not going to find a Script that does what you want. You need to design the process to automate your work-flow and code the script yourself.

JJMack
Participating Frequently
May 30, 2020

code the script yourself...

 

I agree.  But I don't know how to code.  I ask for an advice:  Do you know where can I hire a coder for this?

 

Thanks.