Skip navigation
czlowiekuman
Currently Being Moderated

Array of selected layers - how to get it

Apr 4, 2012 3:43 PM

Hello Everybody

 

I'm looking for a way to get all the selected layers as array.

 

With app.activeDocument.activeLayer i can select only the top-most of the selected layers.

 

 

There is a way to achieve this in ExtendScript:

 

function getSelectedLayers() {
   var layerArray = new Array;
      var desc = new ActionDescriptor();
         var ref = new ActionReference();
         ref.putClass( stringIDToTypeID('layerSection') );
      desc.putReference( charIDToTypeID('null'), ref );
         var layerRef = new ActionReference();
         layerRef.putEnumerated( charIDToTypeID('Lyr '), charIDToTypeID('Ordn'), charIDToTypeID('Trgt') );
      desc.putReference( charIDToTypeID('From'), layerRef );
      executeAction( charIDToTypeID('Mk  '), desc, DialogModes.NO );
   var tempLayerSet = app.activeDocument.activeLayer.layers;
   for ( var layerIndex = 0; layerIndex < tempLayerSet.length; layerIndex++ ) {
      layerArray.push( tempLayerSet[layerIndex] );
   }
   executeAction( charIDToTypeID('undo'), undefined, DialogModes.NO );
   return layerArray;
};

 

 

How can i do that using Photoshop SDK?

 

 

Thanks in advance.

 
Replies
  • Currently Being Moderated
    Apr 5, 2012 11:35 AM   in reply to czlowiekuman

    The JavaScript to C++ conversion is not too difficult. Check out the automation examples. There are suites that you need to acquire for ActionDescriptor(s) and ActionControls(s) and the conversion is almost line by line. Install the Listener plug-in from the SDK and it will generate code just like ScriptListener does for JavaScript. You can use that for a reference.

     
    |
    Mark as:

More Like This

  • Retrieving data ...

Bookmarked By (0)

Answers + Points = Status

  • 10 points awarded for Correct Answers
  • 5 points awarded for Helpful Answers
  • 10,000+ points
  • 1,001-10,000 points
  • 501-1,000 points
  • 5-500 points