Skip to main content
ZayonArts
New Participant
December 12, 2021
Question

Photoshop Script: Layer Visibility

  • December 12, 2021
  • 3 replies
  • 3766 views

Hello guys,

 

I want to create a script that toggles specific layers visibility (multiple layers) based on a single layer visibility, so if i make "Star" layer visible from the group called "VersusVV1" from the artboard called "Versus Images", than will toggle in the same group in same artboard some layers, but else if that layer is visible, will toggle them back to invisible.

 

I found a base code but this is only for layers, but i have more artboards in this PSD and i have 3 duplicated groups with same layer names so i will need to specific from what group to select the layers, as well i have a Left and a Right group, in both groups i have same named layers that needs to be checked, the idea is that i can select what artboard, what group, what other group and what layer to be checked in those groups that will toggle the specific layers, this could make my work easier because i need to modify the PDF frequently and i have too many layers to toggle on and off so to toggle only one layer and the others to toggle after it, would be amazing...

 

This is the base code i found, i haven't tested, i use latest photoshop version from Creative Cloud.

 

So i need like this:

for ArtBoard = "Versus Images"{

  for Group = "VersusVV1"{

    for Group = "Left"{

      if app.documents.layers.item("Stars").visible == true{

         app.documents.layers.item("Stars Logo").visible = true;

         app.documents.layers.item("Stars Shade").visible = true;

         app.documents.layers.item("Stars BG").visible = true;

         app.documents.layers.item("Stars Color").visible = true;

      }

    }

  }

}

 

Base code from what i've got inspired:

 

 

var docs = app.documents;
for (var i = docs.length-1; i >= 0; i--) {
    if(docs[i].layers.item("Chi").visible == true && docs[i].layers.item("Chi").locked == false)
    {
        docs[i].layers.item("Chi").visible = false;
        docs[i].layers.item("Chi").locked = true;
        docs[i].layers.item("Eng").visible = true;
        docs[i].layers.item("Eng").locked = false;
    }
    else if(docs[i].layers.item("Eng").visible == true && docs[i].layers.item("Eng").locked == false)
    {
        docs[i].layers.item("Chi").visible = true;
        docs[i].layers.item("Chi").locked = false;
        docs[i].layers.item("Eng").visible = false;
        docs[i].layers.item("Eng").locked = true;
    }
}
alert("Done.")

 

 

I would be happy if someone could help me out, i am really new to scripting in photoshop but this could help me understand how this works, i need scripts for a lot of my PSD's with this issue so i could make scripts for every one of it that could help me a ton

 

Thank you in advance! Zayon

This topic has been closed for replies.

3 replies

Kukurykus
Brainiac
December 12, 2021

Where have you find this code? It seems to be specific for InDesign: How to make the layer visible on and off

ZayonArts
ZayonArtsAuthor
New Participant
December 12, 2021

That code is from a website called eehelp (i am not doing advertisement, i just said where i got the code from), i saw it as an example for this layer visible/hide script, so i put the code here as an ideea on how i want the code to work, but i need a few other checks before make a layer visible, like checking which artboard i want to check inside of and what group as well, i showed a picture above in a reply to JJMack

JJMack
Community Expert
December 12, 2021

Scripts have no problem processing layers  and changing their  visibility , sizing, warping, masking moving etc.  The thing is automated processes are designed to be used over and over again the do processing you do repeatedly.

 

You do you have a lot of documents the have Identical layer Stacks  you want processed the same way. All the document will have the same layer name in the same stacking order.  Or do documents had different stack structure. Layer name etc.  What does the script depend on so it can do the processing its designed to do. 

 

What exactly are you trying to implement. How is you script design  to be used what is it designed to do. Describe your full automated process.  The script is coded to implement. We need the big picture.  Not that layers visibility may change in the process. Layer names  will they be unique or will the script need to turn  all Layers named  X on or off.  

 

Photoshop have to work on Photoshop Objects with Photoshop methods and properties. Not AI objects or indisigm objects properties and nethods. You need to use Photoshop Scripts methods and Action Manager code to implement your automation. You need a proper design process the will work.

 

 

 

 

JJMack
c.pfaffenbichler
Community Expert
December 12, 2021

Huh? 

I think if you posted screenshots with the pertinent Panels visible to illustrate the visibility-relations of the Layers the whole situation might be clearer. 

 

And I wonder if working with Smart Objects might make the task easier. 

JJMack
Community Expert
December 12, 2021

I added a little code that will help you find errors  in your code

When you run your script the code will help point to errors..

When  I ran your code it showed

 

 

Looking at Layers object I do not see a property element "item"

 

looking a a Layer object  I see a property itemindex  and a name the could be "Chi"

You need to use Adobe Photoshop Object model

JJMack
ZayonArts
ZayonArtsAuthor
New Participant
December 12, 2021

That base code that i gave above is just the an example on how to make visible specific layers based on visibility of others, but i am missing the "for artboard == "Versus Images" && for group "VersusVV1" ", i need to check those layer's visibility in a specific artboard inside specific layer groups... and i want to make them visible based on a layer that i make visible, and so on.

 

Here is what i am talking about as my layers:

But i have 5 layers to make visible for a single layer check, so i will adapt the code for what i need but i have no idea how to build it properly to work how i need it