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

select ant visible layer to avoid General Photoshop error

Engaged ,
Jul 03, 2019 Jul 03, 2019

Copy link to clipboard

Copied

I create a script which cycles through all my layer comps, resize them and save to various folders.

one of the command i use is:

activeDocument.mergeVisibleLayers();

I finally figured out that i would get this error message:

Error: General Photoshop error occurred. This functionality may not be available in this version of Photoshop.

- The command "Merge Visible" is not currently available

when i am running the script when a non visible layer is currently selected.

This can happen when a new layer comp is selected where the active layer should be turned off.

Is there an elegant way to force a selection of a visible layer when the script runs to avoid such errors?

Thanks

TOPICS
Actions and scripting

Views

789

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

Engaged , Jul 03, 2019 Jul 03, 2019

I ended up selecting the top most visible layer like shown below:

function SelectTopVisibleLayer() {

    for (var i = 0; i < activeDocument.layers.length; i++){

        var theLayer = activeDocument.layers;

        if (theLayer.typename === "ArtLayer" ){

            //select a visible layer - any layer

            if(theLayer.visible == true){

                    activeDocument.activeLayer =activeDocument.layers.getByName(theLayer.name);

               break;

            }

        }

    }

}

Votes

Translate

Translate
Adobe
People's Champ ,
Jul 03, 2019 Jul 03, 2019

Copy link to clipboard

Copied

May be suitable

app.activeDocument.flatten();

or

app.activeDocument.artLayers.add();

app.activeDocument.mergeVisibleLayers();

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
Engaged ,
Jul 03, 2019 Jul 03, 2019

Copy link to clipboard

Copied

LATEST

I ended up selecting the top most visible layer like shown below:

function SelectTopVisibleLayer() {

    for (var i = 0; i < activeDocument.layers.length; i++){

        var theLayer = activeDocument.layers;

        if (theLayer.typename === "ArtLayer" ){

            //select a visible layer - any layer

            if(theLayer.visible == true){

                    activeDocument.activeLayer =activeDocument.layers.getByName(theLayer.name);

               break;

            }

        }

    }

}

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