Copy link to clipboard
Copied
Hi to all,
OK, I maybe have issues with my head and need your help on two cases.
First case is nLayers - bLayers = 5 if we know that nLayers is 5 and bLayer is always 0.
nLayers = executeActionGet(ref).getInteger(sTT('numberOfLayers'));
bLayer = executeActionGet(ref).getInteger(sTT('hasBackgroundLayer'));
In the second case nLayers - bLayers = 4 if we also know that nLayers is 5, but now bLayers is TRUE because I already know that 0 = false in JavaScript and negation of 0 is always TRUE.
nLayers = executeActionGet(ref).getInteger(sTT('numberOfLayers'));
bLayer = !executeActionGet(ref).getInteger(sTT('hasBackgroundLayer'));
Does it mean that bLayers now contains the value 1 because it is TRUE or is it something that I don't understand?
Thanks for any info on this,
Makary
var d = new ActionDescriptor();
var r = new ActionReference();
r.putIndex(stringIDToTypeID("layer"), 1); // bottommost layer, not background
d.putReference(stringIDToTypeID("null"), r);
var r1 = new ActionReference();
r1.putIndex(stringIDToTypeID("layer"), app.activeDocument.activeLayer.itemIndex-1); // active layer
d.putReference(stringIDToTypeID("to"), r1);
d.putBoolean(stringIDToTypeID("duplicate"), true);
d.putInteger(stringIDToTypeID("version"), 5); // do not add copy to layer name
executeA
...
Copy link to clipboard
Copied
'hasBackgroundLayer' is BOOLEANTYPE. If there is a background layer, it will be true (1), if not, false (0)
Since you are get this variable as integer and then convert it to boolean with inverse, bLayer variable will contain true if there is no background layer in the document and false if there is one.
Also note that the variable 'numberOfLayers' contains hidden sections that closes each layer group.
Copy link to clipboard
Copied
Now this makes me much more confused as there is always background layer, and that is the bottommost layer in the pallete.
Also what is the meaning of:
"'numberOfLayers' contains hidden sections that closes each layer group."
Copy link to clipboard
Copied
Copy link to clipboard
Copied
I need to make a copy of the bottommost layer which will be placed above the selected layer after the script is executed. I will ask for an example on this because I am totaly lost with now.
Thank you jazz-y and jazz-y and r-bin for giving me purpose to love PS scripting.
Copy link to clipboard
Copied
var d = new ActionDescriptor();
var r = new ActionReference();
r.putIndex(stringIDToTypeID("layer"), 1); // bottommost layer, not background
d.putReference(stringIDToTypeID("null"), r);
var r1 = new ActionReference();
r1.putIndex(stringIDToTypeID("layer"), app.activeDocument.activeLayer.itemIndex-1); // active layer
d.putReference(stringIDToTypeID("to"), r1);
d.putBoolean(stringIDToTypeID("duplicate"), true);
d.putInteger(stringIDToTypeID("version"), 5); // do not add copy to layer name
executeAction(stringIDToTypeID("move"), d, DialogModes.NO);
Copy link to clipboard
Copied
Thank you r-bin as this does the job.
With the comment "bottommost layer, not background" , does it mean that the bottommost layer becomes the background layer after it is locked according to the explanation here?:
https://helpx.adobe.com/photoshop/key-concepts/background.html
Copy link to clipboard
Copied