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

Activate Layers from a specific folder

Community Beginner ,
Sep 27, 2021 Sep 27, 2021

Copy link to clipboard

Copied

I need to create a function to turn on layers from an specific folder when button pressed.

Here is a screenshoot to make it more easy to understand it. ActivateLayers.png

Thanks in advance!

TOPICS
Actions and scripting

Views

357

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 , Sep 28, 2021 Sep 28, 2021
var set = activeDocument.layerSets.getByName("Head");

for (var i = 0; i < set.layers.length; i++) if (set.layers[i].visible) break;

i = (i+1) % set.layers.length;

for (var n = 0; n < set.layers.length; n++) 
    {
    var viz = n==i;
    if (set.layers[n].visible != viz) set.layers[n].visible = viz;
    }

Votes

Translate

Translate
Adobe
Community Expert ,
Sep 27, 2021 Sep 27, 2021

Copy link to clipboard

Copied

You can create an action to show an unselected layer or group.

 

You can also use Layer Comps to set the visiblity, position, appearance, and Layer Comp Selection for Smart Objects. Here's more info on Layer Comps:

Layer comps

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 ,
Sep 27, 2021 Sep 27, 2021

Copy link to clipboard

Copied

An extremely simple option for your case.

 

var set = activeDocument.layerSets.getByName("Head");

for (var i = 0; i < set.layers.length; i++) set.layers[i].visible = true;

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
Community Beginner ,
Sep 28, 2021 Sep 28, 2021

Copy link to clipboard

Copied

Thanks for taking care of this issue! It worked but It turns all "Head" layers inside the group at the same time. Is it possible to turn only one layer at when clicking?

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
LEGEND ,
Sep 28, 2021 Sep 28, 2021

Copy link to clipboard

Copied

If multiple layers have the same name, how would the script know which one to show?

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 ,
Sep 28, 2021 Sep 28, 2021

Copy link to clipboard

Copied

"One layer", which one is it?

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
Community Beginner ,
Sep 28, 2021 Sep 28, 2021

Copy link to clipboard

Copied

My original idea was to change active layer when clicking button (like the attached GIF). I need to create a simple avatar creator, so I will have multiple faces, ears, hairs, etc. It's my first time with PSD scripting. I don't know if it is a better solution for this. Thanks!

toggle.gif

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 ,
Sep 28, 2021 Sep 28, 2021

Copy link to clipboard

Copied

var set = activeDocument.layerSets.getByName("Head");

for (var i = 0; i < set.layers.length; i++) if (set.layers[i].visible) break;

i = (i+1) % set.layers.length;

for (var n = 0; n < set.layers.length; n++) 
    {
    var viz = n==i;
    if (set.layers[n].visible != viz) set.layers[n].visible = viz;
    }

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
Community Beginner ,
Sep 28, 2021 Sep 28, 2021

Copy link to clipboard

Copied

You are awesome! Thank you so much!!

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
LEGEND ,
Sep 28, 2021 Sep 28, 2021

Copy link to clipboard

Copied

Or something completely ridiculous:

head = activeDocument.layerSets.getByName('Head'); lrs = [].slice.call(ntve = head.artLayers)
function v(v) {return (eval(({1: 'lyr', 2: 'lrs.shift()', 3: 'ntve[0]'})[v]).visible ^= 1) + 1}
while(lrs.length) (lyr = lrs.shift()).visible && v(1) && ((lrs.length && v(2)) || v(3))

 

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
Community Beginner ,
Sep 28, 2021 Sep 28, 2021

Copy link to clipboard

Copied

It worked too! Thanks

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
Community Expert ,
Sep 27, 2021 Sep 27, 2021

Copy link to clipboard

Copied

By the way, folder inside Ps document is called 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
Community Expert ,
Sep 28, 2021 Sep 28, 2021

Copy link to clipboard

Copied

I suggest you take a look at Photoshop's Layer Comp feature.

Layer comps

warmly/j

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
LEGEND ,
Sep 28, 2021 Sep 28, 2021

Copy link to clipboard

Copied

LATEST

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