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

Activate Layers from a specific folder

Community Beginner ,
Sep 27, 2021 Sep 27, 2021

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
579
Translate
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;
    }
Translate
Adobe
Community Expert ,
Sep 27, 2021 Sep 27, 2021

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

Translate
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

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

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?

Translate
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

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

Translate
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

"One layer", which one is it?

Translate
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

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

Translate
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
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;
    }
Translate
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

You are awesome! Thank you so much!!

Translate
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

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

 

Translate
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

It worked too! Thanks

Translate
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

By the way, folder inside Ps document is called layer group.

Translate
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

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

Layer comps

warmly/j

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