Copy link to clipboard
Copied
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.
// 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 theNa
...
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
»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?
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
// 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
};
Copy link to clipboard
Copied
Thans for your help c_pfaffenbichler.
Tested and worked. Thanks.
I dare to ask for further work. In the beginning I did not write down all the workflow needed.
So I ask if you can help me more. To make this script more complex. Preserve stack order of layers the same as the order stack inside the paths. After that I proceed to create groups with masks and rename them accordingly.
1st stage. I have a pixel layer.
2 nd stage. I draw path shapes.
3 rd stage. I build a folder/layer stack with mask applied to groups. Each group have a copy of the layer I had on the 1st stage. I create another group with filled 2 shapes based on the paths (one of them is an inverted selection, filled).
A screenshot of the final stack.
I attached 3 psd files. Each one have the different stages of how the layer stacks ends up. If it helps you follow the steps.
And extra backup of the psd files:
https://www.dropbox.com/s/twm90crc1i40bwp/path-groups-psd.zip?dl=0
Stack order and name convention is the key of the workflow. As I use this as a standard within a teamwork.
Let me know if this is something you have the time to build, and if there is a way to payback for your help.
Pd:
My native languange is not english, but spanish. Let me know if some explanations are not well done.
Copy link to clipboard
Copied
To change the order of the Groups you can change the line
for (var m = 0; m < thePaths.length; m++) {
to
for (var m = thePaths.length - 1; m >= 0; m--) {
As for the whole rest of the changes you could start a new thread to ask for assistance in making the further adjustments.
One question though:
Couldn’t the »… ++++«-Layers be Shape Layers with the corresponding Path as Vector Mask instead of pixel layers?
// create one group per path with the path’s name and a shape layer within;
// 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 = thePaths.length - 1; m >= 0; 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 );
// create shape layer;
var desc2 = new ActionDescriptor();
var ref1 = new ActionReference();
ref1.putIdentifier( stringIDToTypeID( "path" ), thePaths[m][1] );
desc2.putReference( stringIDToTypeID( "null" ), ref1 );
executeAction( stringIDToTypeID( "select" ), desc2, DialogModes.NO );
var theLayer = createShapeLayer(theName+" ++++", 0, 255, 255);
// select above;
var desc6 = new ActionDescriptor();
var ref4 = new ActionReference();
ref4.putEnumerated( charIDToTypeID( "Lyr " ), charIDToTypeID( "Ordn" ), charIDToTypeID( "Bckw" ) );
desc6.putReference( charIDToTypeID( "null" ), ref4 );
executeAction( charIDToTypeID( "slct" ), desc6, DialogModes.NO );
}
};
////// collect paths //////
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
};
////// create a solid color layer //////
function createShapeLayer(theName, theR, theG, theB) {
// solid color layer;
var desc16 = new ActionDescriptor();
var ref4 = new ActionReference();
ref4.putClass( stringIDToTypeID( "contentLayer" ) );
desc16.putReference( charIDToTypeID( "null" ), ref4 );
var desc17 = new ActionDescriptor();
var desc18 = new ActionDescriptor();
var desc19 = new ActionDescriptor();
desc19.putDouble( charIDToTypeID( "Rd " ), theR );
desc19.putDouble( charIDToTypeID( "Grn " ), theG );
desc19.putDouble( charIDToTypeID( "Bl " ), theB );
desc18.putObject( charIDToTypeID( "Clr " ), charIDToTypeID( "RGBC" ), desc19 );
var idsolidColorLayer = stringIDToTypeID( "solidColorLayer" );
desc17.putObject( charIDToTypeID( "Type" ), idsolidColorLayer, desc18 );
desc17.putString( charIDToTypeID( "Nm " ), theName);
desc16.putObject( charIDToTypeID( "Usng" ), stringIDToTypeID( "contentLayer" ), desc17 );
executeAction( charIDToTypeID( "Mk " ), desc16, DialogModes.NO );
return activeDocument.activeLayer
};
Copy link to clipboard
Copied
»Couldn’t the … ++++-Layers be Shape Layers with the corresponding Path as Vector Mask instead of pixel layers?«
I did not explained the use of the masks, sorry. I use them inside the liquify filter. Inside the option "Show Backdrop" -> "use" I select the pixel layer. Here the pixel layer shape helps me view the edge of the area I'm working in. But if I use a Shape layer, the filter completely paints the backdrop with the shape color, not taking account of the path. So I can't see the shape I'm working in within the Liquify filter.
for (var m = 0; m < thePaths.length; m++) {
to
for (var m = thePaths.length - 1; m >= 0; m--) {
This worked.
The new script is halfway to a complete solution for my repetitive tasks. Which is more than I though i would get. Thanks for your time and help.
Copy link to clipboard
Copied
Just an update. This script helped me a lot. As JJMack mentioned "You need to design the process to automate your work-flow".
That is what I will do. Refine my process before moving forward. Then I can share how it is used.