Highlighted

Subtraction of layers is not the same if negation is present

Community Beginner ,
Oct 18, 2020

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

Adobe Community Professional
Correct answer by r-bin | Adobe Community Professional
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);
TOPICS
Actions and scripting, How to, Windows

Views

1.5K

Likes

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

Subtraction of layers is not the same if negation is present

Community Beginner ,
Oct 18, 2020

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

Adobe Community Professional
Correct answer by r-bin | Adobe Community Professional
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);
TOPICS
Actions and scripting, How to, Windows

Views

1.5K

Likes

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
Oct 18, 2020 0
Enthusiast ,
Oct 18, 2020

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.

Likes

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
Reply
Loading...
Oct 18, 2020 1
Community Beginner ,
Oct 19, 2020

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."

Likes

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
Reply
Loading...
Oct 19, 2020 0
Adobe Community Professional ,
Oct 18, 2020

Copy link to clipboard

Copied

The question is not clear.

Do you want to check this out
alert ((5 - false) + " " + (5 - true))


In fact, you need to use getBoolean to access 'hasBackgroundLayer'.

In the first case, you use getInterger, which gives you options for the bLayer variable 0 or 1 (not false and true).
If you use the "!" operator then the result will always be either false or true.

P.S. Note that not all versions of Photoshop support the 'hasBackgroundLayer' property. It is better to use the "count" property of the layer to determine the actual number of layers.
 

Likes

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
Reply
Loading...
Oct 18, 2020 2
Community Beginner ,
Oct 19, 2020

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.

Likes

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
Reply
Loading...
Oct 19, 2020 0
Adobe Community Professional ,
Oct 19, 2020

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);

Likes

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
Reply
Loading...
Oct 19, 2020 1
Community Beginner ,
Oct 20, 2020

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

Likes

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
Reply
Loading...
Oct 20, 2020 0
r-bin LATEST
Adobe Community Professional ,
Oct 20, 2020

Copy link to clipboard

Copied

This means that this script does not copy the Background layer (even if it exists). Background, if present, has index 0 (sort of like this). But you won't be able to copy it this way (for an unknown reason).
Also, the script needs to be redone if the bottom layer is located in a folder (folders), otherwise there will be an error too.
 

Likes

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
Reply
Loading...
Oct 20, 2020 0