Unexpected behavior...

Anyone, especially newbies, asking for help with Photoshop Scripting and Photoshop Automation - as opposed to those contributing to discussion about an aspect of Photoshop Scripting

Moderators: Tom, Kukurykus

mwcarroll
Posts: 2
Joined: Tue Oct 05, 2021 7:38 am

Unexpected behavior...

Post by mwcarroll »

I have attempted to write a script that will take the selected layers and create a pixel selection from them. This works fine for one or more individual layers selected.

When I detect that a LayerSet is selected, I grab all children indices and pass those instead of the index of the LayerSet to be turned into a selection. This should behave the same as if the individual layers inside the LayerSet are selected, but what ultimately happens is the entire document is turned into a selection.

Can anyone help me figure out what I've done wrong?

Code provided here: https://gist.github.com/mwcarroll/cc190 ... 920bd4fcb9

Professional AI Audio Generation within Adobe Premiere Pro - Download Free Plugin here

User avatar
Kukurykus
Posts: 528
Joined: Mon Jul 25, 2016 12:36 pm

Re: Unexpected behavior...

Post by Kukurykus »

If you have no background layer you may change your two functions to:

Code: Select all

function clearSelection() {
    var dialogMode = DialogModes.NO;
    var desc1 = new ActionDescriptor();
    var ref1 = new ActionReference();
    ref1.putProperty(cTID('Chnl'), sTID("selection"));
    desc1.putReference(cTID('null'), ref1);
    var ref2 = new ActionReference();
    ref2.putEnumerated(cTID('Chnl'), cTID('Chnl'), cTID('Trsp'));
    ref2.putIndex(cTID('Lyr '), selectedLayersIdxs[selectedLayersIdxs.length - 1])
    desc1.putReference(cTID('T   '), ref2);
    executeAction(cTID('setd'), desc1, dialogMode);
}

function addToSelectionByIdx(idx) {
    var dialogMode = DialogModes.NO;
    var desc1 = new ActionDescriptor();
    var ref1 = new ActionReference();
    ref1.putEnumerated(sTID('channel'), sTID('channel'), sTID('transparencyEnum'));
    ref1.putIndex(cTID('Lyr '), idx);
    desc1.putReference(cTID('null'), ref1);
    var ref2 = new ActionReference();
    ref2.putProperty(cTID('Chnl'), sTID("selection"));
    desc1.putReference(cTID('T   '), ref2);
    executeAction(cTID('Add '), desc1, dialogMode);
}
mwcarroll
Posts: 2
Joined: Tue Oct 05, 2021 7:38 am

Re: Unexpected behavior...

Post by mwcarroll »

Perfect! Thank you Kukurykus!