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

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

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

TOPICS
Actions and scripting

Views

521

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

Valorous Hero , Nov 16, 2020 Nov 16, 2020

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"), stri
...

Votes

Translate

Translate
Adobe
Community Beginner ,
Nov 16, 2020 Nov 16, 2020

Copy link to clipboard

Copied

script_question.jpg

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
Valorous Hero ,
Nov 16, 2020 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);

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

Copy link to clipboard

Copied

LATEST

That works perfectly, thanks! 

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