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

How to define a certain layer is selected or not?

Participant ,
Jun 11, 2013 Jun 11, 2013

Copy link to clipboard

Copied

If you click outside of the open document, then on the layers' panel untagged about which layer is active, some are blocked by filters, but in the properties of the active layer of a document. In his instrument I want to also block some of the controls in case you explicitly select one of the layers (not marked in the layers' panel)

TOPICS
Actions and scripting

Views

1.2K

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

Valorous Hero , Jun 12, 2013 Jun 12, 2013

This will give you a list of selected layers, the array will be zero if no layers are selected.

var selectedLayer =  getSelectedLayersIdx();

if(!selectedLayer.length) alert("no layers selected");

function getSelectedLayersIdx(){

      var selectedLayers = new Array;

      var ref = new ActionReference();

      ref.putEnumerated( charIDToTypeID("Dcmn"), charIDToTypeID("Ordn"), charIDToTypeID("Trgt") );

      var desc = executeActionGet(ref);

      if( desc.hasKey( stringIDToTypeID( 'targetLayers' )

...

Votes

Translate

Translate
Adobe
Community Expert ,
Jun 11, 2013 Jun 11, 2013

Copy link to clipboard

Copied

I don’t seem to understand what you are asking.

Could you please elaborate, mabe provide screenshots or sketches to illustrate the issue?

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
Participant ,
Jun 12, 2013 Jun 12, 2013

Copy link to clipboard

Copied

jn this video you can see what menu Filters are blkcked if no layer is selected.

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
Valorous Hero ,
Jun 12, 2013 Jun 12, 2013

Copy link to clipboard

Copied

This will give you a list of selected layers, the array will be zero if no layers are selected.

var selectedLayer =  getSelectedLayersIdx();

if(!selectedLayer.length) alert("no layers selected");

function getSelectedLayersIdx(){

      var selectedLayers = new Array;

      var ref = new ActionReference();

      ref.putEnumerated( charIDToTypeID("Dcmn"), charIDToTypeID("Ordn"), charIDToTypeID("Trgt") );

      var desc = executeActionGet(ref);

      if( desc.hasKey( stringIDToTypeID( 'targetLayers' ) ) ){

         desc = desc.getList( stringIDToTypeID( 'targetLayers' ));

          var c = desc.count

          var selectedLayers = new Array();

          for(var i=0;i<c;i++){

            try{

               activeDocument.backgroundLayer;

               selectedLayers.push(  desc.getReference( i ).getIndex() );

            }catch(e){

               selectedLayers.push(  desc.getReference( i ).getIndex()+1 );

            }

          }

       }else{

         var ref = new ActionReference();

         ref.putProperty( charIDToTypeID("Prpr") , charIDToTypeID( "ItmI" ));

         ref.putEnumerated( charIDToTypeID("Lyr "), charIDToTypeID("Ordn"), charIDToTypeID("Trgt") );

         try{

            activeDocument.backgroundLayer;

            selectedLayers.push( executeActionGet(ref).getInteger(charIDToTypeID( "ItmI" ))-1);

         }catch(e){

            selectedLayers.push( executeActionGet(ref).getInteger(charIDToTypeID( "ItmI" )));

         }

     var vis = app.activeDocument.activeLayer.visible;

        if(vis == true) app.activeDocument.activeLayer.visible = false;

        var desc9 = new ActionDescriptor();

    var list9 = new ActionList();

    var ref9 = new ActionReference();

    ref9.putEnumerated( charIDToTypeID('Lyr '), charIDToTypeID('Ordn'), charIDToTypeID('Trgt') );

    list9.putReference( ref9 );

    desc9.putList( charIDToTypeID('null'), list9 );

    executeAction( charIDToTypeID('Shw '), desc9, DialogModes.NO );

    if(app.activeDocument.activeLayer.visible == false) selectedLayers.shift();

        app.activeDocument.activeLayer.visible = vis;

      }

      return selectedLayers;

};

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
Participant ,
Jul 20, 2013 Jul 20, 2013

Copy link to clipboard

Copied

I'm sorry for longest timeout 🙂

After I'm started this script in the row "var ref = new ActionReference();" is error -  ActionReference has no a cinstructor. What I can do ?

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
Guru ,
Jul 20, 2013 Jul 20, 2013

Copy link to clipboard

Copied

Where are you running the script from? If you are using ESKT make sure Photoshop is the target app or add #target photoshop at the top of the script.

As far as I know only Photoshop has an ActionReference class. If another app is running the script you will get that error. The default target app for ESTK is ESTK itself.

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
Participant ,
Jul 20, 2013 Jul 20, 2013

Copy link to clipboard

Copied

LATEST

Yes ! Thanks !

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