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

Photoshop Script: Layer Visibility

New Here ,
Dec 11, 2021 Dec 11, 2021

Copy link to clipboard

Copied

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

TOPICS
Actions and scripting , Windows

Views

2.7K

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
Adobe
Community Expert ,
Dec 12, 2021 Dec 12, 2021

Copy link to clipboard

Copied

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

image.png

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

When  I ran your code it showed

image.png

 

image.png

image.png

 

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

image.png

JJMack

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
New Here ,
Dec 12, 2021 Dec 12, 2021

Copy link to clipboard

Copied

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:

Screenshot_4.png

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

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 ,
Dec 12, 2021 Dec 12, 2021

Copy link to clipboard

Copied

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. 

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 ,
Dec 12, 2021 Dec 12, 2021

Copy link to clipboard

Copied

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

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
New Here ,
Dec 12, 2021 Dec 12, 2021

Copy link to clipboard

Copied

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

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 ,
Dec 12, 2021 Dec 12, 2021

Copy link to clipboard

Copied

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

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
New Here ,
Dec 13, 2021 Dec 13, 2021

Copy link to clipboard

Copied

LATEST

I will try to explain as best as i can on what i want the script to do for me...

 

Here is a screenshoot from my photoshop from the image and the layer groups on the right side that you can see the base of what i try to do, i will try to illustrate every step that i make, i tried to make it as simple as possible, i maybe coud've done it in another way but some PSD files that i work on have the same structure but more complicated in layering so i can't really modify them as i wish

 

Screenshot_5.png

As you can see, i have this Versus called image, i have 6 teams, so i made the teams to be on the left and duplicated on the right side of it as well, i also have from the organisation all the upcoming games and how the teams are playing, so i need always to put the right teams in the right sides, so what i did is i made firstly the "Versus 1" Group, made everything on that one and then duplicated it but renamed the groups, inside the groups i have the same layer names.

 

Answer for this "Layer names  will they be unique or will the script need to turn  all Layers named  X on or off.":

- Layer names will be unique, so if i turn on the text layer called "5 Oite", i want that the other layers with the logos to turn on as well, those layers will have unique names, the logo's are smart object type layers, in thee image below i showed again a picture of the layers, right under the "Versus 1" group is a group called "T Right", that means teams on the right side if the Versus, i have also a "T Left" for the left side, si the text that i turn on the right side, i want to turn on the layers for the right side, that means from a specific named group of layers to turn on another specific group's layers, like i turn on "Right Names"s group, "5 Oite" text layer, that will turn on the "T Right"'s group, "5 Oite" and "5 Oite copy" smart object type layers...

 

Screenshot_6.png

 

Indeed this type of file could.ve been more simplified but i have more complex files that i need to activate around 10 layers at a time and hide another 10 just for a single modification, this kind of file tooks me a lot of time to modify, so i want to have somehow a base code that i can expand depending on my file that i work on, also is not needed to be automated like if i hide a layer instantly hides the other ones too, i can just make visible and hide some layers and at the final to run the script that chesk the layers and do the rest of the job, i don't want to complicate myself by trying to fully automate it, just simple script that i run at the final, that is enough.

 

All what i try to do is that to be easier to modify the project file as fast as possible, not spending 15 minutes to make the modifications, i try to reduce these 15 minutes into let's say 2 minutes of work by running a script based on some layers visibility and than i just hit "Quick export as PNG" and that to be it.

 

I hope i could explain it quite ok, i just need a base code that i can expand myself, the problem is that i don't know how to properly build the script to check for everything i want and then to modify what i need to be modified because i work a lot with artboards, this PSD file is having 500+ MB in size, in the layer side you can see that i have some other artboards too, and that's why i want the script to check a specific artboard and to check specific group of layers on unique names that i will give them

 

Zayon

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 ,
Dec 12, 2021 Dec 12, 2021

Copy link to clipboard

Copied

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