• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Subtraction of layers is not the same if negation is present

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

TOPICS
Actions and scripting , Windows

Views

1.8K

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
community guidelines

correct answers 1 Correct answer

People's Champ , Oct 19, 2020 Oct 19, 2020
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
...

Votes

Translate

Translate
Adobe
Guide ,
Oct 18, 2020 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.

Votes

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
community guidelines
Explorer ,
Oct 19, 2020 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."

Votes

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
community guidelines
People's Champ ,
Oct 18, 2020 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.
 

Votes

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
community guidelines
Explorer ,
Oct 19, 2020 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.

Votes

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
community guidelines
People's Champ ,
Oct 19, 2020 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);

Votes

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
community guidelines
Explorer ,
Oct 20, 2020 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

Votes

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
community guidelines
People's Champ ,
Oct 20, 2020 Oct 20, 2020

Copy link to clipboard

Copied

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

Votes

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
community guidelines