Highlighted

Need help to modify a script to create new group and layers within an existing group

Community Beginner ,
Nov 16, 2020

Copy link to clipboard

Copied

Hi, 

I have a script that I am using within an action to create a new group containing the selected layer, and  make the name of that group the same as the layer name. After that I create 3 different layers within the group using actions. 

 

It works great, except that the new group isn't created within the existing group heirarchy - it created at the lowest level. For example my group structure is 'animals > cats', and my layer within cats is 'tabby' but when I run the script on the layer 'tabby', it is moved out of animals>cats. How can I alter the script so that the new group stays in the same place as the layer is is created from? I am using Photoshop 2020 21.01

 

Here is the script:

#target photoshop
main();
function main(){
if(!documents.length) return;
var doc = activeDocument;
if(doc.activeLayer.kind != LayerKind.NORMAL) return;
var layerRef = doc.activeLayer;
var layerSetRef = doc.layerSets.add();
layerSetRef.name = layerRef.name;
layerRef.move(layerSetRef, ElementPlacement.PLACEATEND); 
}

 

Thanks!!!

Adobe Community Professional
Correct answer by r-bin | Adobe Community Professional

Try this

var d = new ActionDescriptor();
var r = new ActionReference();
r.putClass(stringIDToTypeID("layerSection"));
d.putReference(stringIDToTypeID("null"), r);
var r1 = new ActionReference();
r1.putEnumerated(stringIDToTypeID("layer"), stringIDToTypeID("ordinal"), stringIDToTypeID("targetEnum"));
d.putReference(stringIDToTypeID("from"), r1);
var d1 = new ActionDescriptor();
d1.putString(stringIDToTypeID("name"), app.activeDocument.activeLayer.name);
d.putObject(stringIDToTypeID("using"), stringIDToTypeID("layerSection"), d1);
executeAction(stringIDToTypeID("make"), d, DialogModes.NO);
TOPICS
Actions and scripting, How to

Views

38

Likes

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

Need help to modify a script to create new group and layers within an existing group

Community Beginner ,
Nov 16, 2020

Copy link to clipboard

Copied

Hi, 

I have a script that I am using within an action to create a new group containing the selected layer, and  make the name of that group the same as the layer name. After that I create 3 different layers within the group using actions. 

 

It works great, except that the new group isn't created within the existing group heirarchy - it created at the lowest level. For example my group structure is 'animals > cats', and my layer within cats is 'tabby' but when I run the script on the layer 'tabby', it is moved out of animals>cats. How can I alter the script so that the new group stays in the same place as the layer is is created from? I am using Photoshop 2020 21.01

 

Here is the script:

#target photoshop
main();
function main(){
if(!documents.length) return;
var doc = activeDocument;
if(doc.activeLayer.kind != LayerKind.NORMAL) return;
var layerRef = doc.activeLayer;
var layerSetRef = doc.layerSets.add();
layerSetRef.name = layerRef.name;
layerRef.move(layerSetRef, ElementPlacement.PLACEATEND); 
}

 

Thanks!!!

Adobe Community Professional
Correct answer by r-bin | Adobe Community Professional

Try this

var d = new ActionDescriptor();
var r = new ActionReference();
r.putClass(stringIDToTypeID("layerSection"));
d.putReference(stringIDToTypeID("null"), r);
var r1 = new ActionReference();
r1.putEnumerated(stringIDToTypeID("layer"), stringIDToTypeID("ordinal"), stringIDToTypeID("targetEnum"));
d.putReference(stringIDToTypeID("from"), r1);
var d1 = new ActionDescriptor();
d1.putString(stringIDToTypeID("name"), app.activeDocument.activeLayer.name);
d.putObject(stringIDToTypeID("using"), stringIDToTypeID("layerSection"), d1);
executeAction(stringIDToTypeID("make"), d, DialogModes.NO);
TOPICS
Actions and scripting, How to

Views

39

Likes

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
Nov 16, 2020 0
Community Beginner ,
Nov 16, 2020

Copy link to clipboard

Copied

script_question.jpg

Likes

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
Reply
Loading...
Nov 16, 2020 0
Adobe Community Professional ,
Nov 16, 2020

Copy link to clipboard

Copied

Try this

var d = new ActionDescriptor();
var r = new ActionReference();
r.putClass(stringIDToTypeID("layerSection"));
d.putReference(stringIDToTypeID("null"), r);
var r1 = new ActionReference();
r1.putEnumerated(stringIDToTypeID("layer"), stringIDToTypeID("ordinal"), stringIDToTypeID("targetEnum"));
d.putReference(stringIDToTypeID("from"), r1);
var d1 = new ActionDescriptor();
d1.putString(stringIDToTypeID("name"), app.activeDocument.activeLayer.name);
d.putObject(stringIDToTypeID("using"), stringIDToTypeID("layerSection"), d1);
executeAction(stringIDToTypeID("make"), d, DialogModes.NO);

Likes

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
Reply
Loading...
Nov 16, 2020 2
jendart LATEST
Community Beginner ,
Nov 16, 2020

Copy link to clipboard

Copied

That works perfectly, thanks! 

Likes

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
Reply
Loading...
Nov 16, 2020 0