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!!!
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
...
Copy link to clipboard
Copied
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);
Copy link to clipboard
Copied
That works perfectly, thanks!