1 Reply Latest reply on Sep 24, 2012 10:13 AM by Paul Riggott

    Selecting top layer (after selecting all layers)

    Ghoulfool Level 1

      Here's an odd thing: I found that


      app.activeDocument.activeLayer = app.activeDocument.layers[0];


      Works fine (as you would expect) in selecting the topmost layer, but fails to do just that after all layers have been selected.


      var id98 = stringIDToTypeID( "selectAllLayers" );
      var desc25 = new ActionDescriptor();
      var id99 = charIDToTypeID( "null" );
      var ref19 = new ActionReference();
      var id100 = charIDToTypeID( "Lyr " );
      var id101 = charIDToTypeID( "Ordn" );
      var id102 = charIDToTypeID( "Trgt" );
      ref19.putEnumerated( id100, id101, id102 );
      desc25.putReference( id99, ref19 );
      executeAction( id98, desc25, DialogModes.NO );
      // uncomment this to select the second layer and the code will work
      // app.activeDocument.activeLayer = app.activeDocument.layers[1]; 
      app.activeDocument.activeLayer = app.activeDocument.layers[0];


      Anyone know why this is the case?

        • 1. Re: Selecting top layer (after selecting all layers)
          Paul Riggott Level 6

          No idea why it should do this, but here is an alternative...



          function selectTopLayer(){
          var ref = new ActionReference(); 
          ref.putEnumerated( charIDToTypeID('Dcmn'), charIDToTypeID('Ordn'), charIDToTypeID('Trgt') ); 
          var count = executeActionGet(ref).getInteger(charIDToTypeID('NmbL'));
          var ref2 = new ActionReference();
          ref2.putIndex(charIDToTypeID('Lyr '), count);
          var desc = new ActionDescriptor();
          desc.putReference(charIDToTypeID('null'), ref2 );
          desc.putBoolean( charIDToTypeID( 'MkVs' ), false ); 
          executeAction(charIDToTypeID('slct'), desc, DialogModes.NO );