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
Unexpected behavior...
Re: Unexpected behavior...
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);
}
Re: Unexpected behavior...
Perfect! Thank you Kukurykus!