Skip to main content
Inspiring
February 11, 2016
Answered

get only the 'targetLayers' key from 'Dcmn' descriptor

  • February 11, 2016
  • 1 reply
  • 726 views

Hi I'm working with very big documents, with a lot of layers, and I have a problem when trying to get the 'targetLayers' key from the 'Dcmn' descriptor Photoshop it's Building Histograms and this takes a lot of time, only for getting the selected layers...:( I know that there is the putProperty method, which works fine for Layers('Lyr ') or the Application('capp') but doesn't seam to work with documents

Does anyone has any idea on how to get only the 'targetLayers' key?

This is the code to get the selected layers indexes:

function getSelectedLayersIdx(){// get the selected layers index( positon in layer editor)

     var selectedLayers = new Array;

     var ref = new ActionReference();

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

     var desc = executeActionGet(ref);

     var add = 1;

     if(hasBackground()){add = 0}

     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++){

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

          }

     }else{

          var ref = new ActionReference();

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

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

          srs = hasBackground()?executeActionGet(ref).getInteger(charIDToTypeID( 'ItmI' ))-1:executeActionGet(ref).getInteger(charIDToTypeID( 'ItmI' ));

          selectedLayers.push( srs);

     }

     return selectedLayers;

}

and if I put this:

     var ref = new ActionReference();

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

     ref.putProperty(charIDToTypeID('Prpr'), stringIDToTypeID('targetLayers'));

     var desc = executeActionGet(ref);

I get the error saying that "- The command "Get" is not currently available."

This topic has been closed for replies.
Correct answer
var ref = new ActionReference();  
ref.putEnumerated( charIDToTypeID('Dcmn'), charIDToTypeID('Ordn'), charIDToTypeID('Trgt') );  
ref.putProperty(charIDToTypeID('Prpr'), stringIDToTypeID('targetLayers'));  
var desc = executeActionGet(ref);

I get the error saying that "- The command "Get" is not currently available."

When building a reference object, the right ordering of containers is critical; it goes from specific to general. Think of it with "of" inserted : get the target layers property of the current document.

This should work then:

var ref = new ActionReference();  
ref.putProperty(charIDToTypeID('Prpr'), stringIDToTypeID('targetLayers'));  
ref.putEnumerated( charIDToTypeID('Dcmn'), charIDToTypeID('Ordn'), charIDToTypeID('Trgt') );  
var desc = executeActionGet(ref);

HTH...

1 reply

Correct answer
February 11, 2016
var ref = new ActionReference();  
ref.putEnumerated( charIDToTypeID('Dcmn'), charIDToTypeID('Ordn'), charIDToTypeID('Trgt') );  
ref.putProperty(charIDToTypeID('Prpr'), stringIDToTypeID('targetLayers'));  
var desc = executeActionGet(ref);

I get the error saying that "- The command "Get" is not currently available."

When building a reference object, the right ordering of containers is critical; it goes from specific to general. Think of it with "of" inserted : get the target layers property of the current document.

This should work then:

var ref = new ActionReference();  
ref.putProperty(charIDToTypeID('Prpr'), stringIDToTypeID('targetLayers'));  
ref.putEnumerated( charIDToTypeID('Dcmn'), charIDToTypeID('Ordn'), charIDToTypeID('Trgt') );  
var desc = executeActionGet(ref);

HTH...

cbuliarcaAuthor
Inspiring
February 11, 2016

That's great thank you for explain it to me, it's simple and clear. Now it works fast.