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

Script to toggle visibility of the layer below

New Here ,
Jul 15, 2022 Jul 15, 2022

Copy link to clipboard

Copied

Hello!

I would like to know if anyone knows a script or another way to make the layer below the selected one to toggle its visibility, because I am running an action to many files and the last one needs to be duplicated constantly, but it has transparency so I need to manually toggle the layer all the time.

TOPICS
Windows

Views

215

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

Community Expert , Jul 15, 2022 Jul 15, 2022

@KingOfCanvas 

 

Try the following script:

 

/*
Toggle Visibility of Previous Layer.jsx
https://community.adobe.com/t5/photoshop-ecosystem-discussions/script-to-toggle-visibility-of-the-layer-below/td-p/13072521
Stephen Marsh, 16th July 2022, Version 1
*/

if (activeDocument.layers.length > 1) {

    try {

        selectLayerByIndex(getActiveLayerIndex() - 1);
        activeDocument.activeLayer.visible = !activeDocument.activeLayer.visible
        selectLayerByIndex(getActiveLayerIndex() + 1);
...

Votes

Translate

Translate
Adobe
Community Expert ,
Jul 15, 2022 Jul 15, 2022

Copy link to clipboard

Copied

@KingOfCanvas 

 

Try the following script:

 

/*
Toggle Visibility of Previous Layer.jsx
https://community.adobe.com/t5/photoshop-ecosystem-discussions/script-to-toggle-visibility-of-the-layer-below/td-p/13072521
Stephen Marsh, 16th July 2022, Version 1
*/

if (activeDocument.layers.length > 1) {

    try {

        selectLayerByIndex(getActiveLayerIndex() - 1);
        activeDocument.activeLayer.visible = !activeDocument.activeLayer.visible
        selectLayerByIndex(getActiveLayerIndex() + 1);

        function selectLayerByIndex(index) {
            /* https://github.com/ES-Collection/Photoshop-Scripts/blob/master/Remove%20Unused%20Layers.jsx */
            var c2t = function (s) {
                return app.charIDToTypeID(s);
            };
            var s2t = function (s) {
                return app.stringIDToTypeID(s);
            };
            var descriptor = new ActionDescriptor();
            var reference = new ActionReference();
            reference.putIndex(s2t("layer"), index);
            descriptor.putReference(c2t("null"), reference);
            descriptor.putBoolean(s2t("makeVisible"), false);
            executeAction(s2t("select"), descriptor, DialogModes.NO);
        }

        function getActiveLayerIndex() {
            /* https://github.com/Paul-Riggott/PS-Scripts/blob/master/getLayersetLayerIDs.jsx */
            var ref = new ActionReference();
            ref.putEnumerated(charIDToTypeID('Lyr '), charIDToTypeID('Ordn'), charIDToTypeID('Trgt'));
            try {
                activeDocument.backgroundLayer;
                return executeActionGet(ref).getInteger(charIDToTypeID("ItmI")) - 1;
            } catch (e) {
                return executeActionGet(ref).getInteger(charIDToTypeID("ItmI"));
            }
        }

    } catch (e) { }
    
}

 

I'm sure that there is a more direct, less verbose approach...

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 ,
Jul 18, 2022 Jul 18, 2022

Copy link to clipboard

Copied

LATEST

Thank you so much, it works perfectly!

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