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

JSX - Find All - Active Layers

Explorer ,
Feb 26, 2025 Feb 26, 2025

Copy link to clipboard

Copied

Hello,

 

Is there a way to find all active layers with JSX?  The 'doc.activeLayer' function seems to target only the first activeLayer in the layer panel


Thanks


Screenshot 2025-02-26 at 7.54.09 PM.pngexpand image

TOPICS
Actions and scripting , macOS , Windows

Views

88
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

Community Expert , Feb 26, 2025 Feb 26, 2025

This is the code to get the information (JavaScript Object) of selected layers in Layer panel. id and index are there, so you may be able to refer to the ExtendScript Layer from it.

/**
  * @Version 1.0.0
  * @author sttk3.com
*/

/**
  * Get the ActionDescriptor of the selected layer of activeDocument
  * @Return {Array<any>} [
  *   {name: string, index: number, id: number, desc: ActionDescriptor}...
  * ]
*/
function getSelectedLayerDesc() {
  var res = [] ;

  var ref1 = new ActionReference(
...

Votes

Translate
Adobe
Community Expert ,
Feb 26, 2025 Feb 26, 2025

Copy link to clipboard

Copied

This is the code to get the information (JavaScript Object) of selected layers in Layer panel. id and index are there, so you may be able to refer to the ExtendScript Layer from it.

/**
  * @Version 1.0.0
  * @author sttk3.com
*/

/**
  * Get the ActionDescriptor of the selected layer of activeDocument
  * @Return {Array<any>} [
  *   {name: string, index: number, id: number, desc: ActionDescriptor}...
  * ]
*/
function getSelectedLayerDesc() {
  var res = [] ;

  var ref1 = new ActionReference() ;
  var idTargetLayers = stringIDToTypeID('targetLayers') ;
  ref1.putProperty(stringIDToTypeID('property'), idTargetLayers) ;
  ref1.putEnumerated(stringIDToTypeID('document'), stringIDToTypeID('ordinal'), stringIDToTypeID('targetEnum')) ;
  var targetLayers = executeActionGet(ref1).getList(idTargetLayers) ;

  // if there is a background layer, add 1 to index
  var backgroundFactor = 0 ;
  try {
    activeDocument.backgroundLayer ;
  } catch(e) {
    backgroundFactor = 1 ;
  }

  var ref2, tempIndex, desc, layerItem ;
  for(var i = 0, len = targetLayers.count ; i < len ; i++) {
    ref2 = new ActionReference() ;
    tempIndex = targetLayers.getReference(i).getIndex() + backgroundFactor ;
    ref2.putIndex(stringIDToTypeID('layer'), tempIndex) ;
    desc = executeActionGet(ref2) ;

    layerItem = {
      name: desc.getString(stringIDToTypeID('name')), 
      index: tempIndex, 
      id: desc.getInteger(stringIDToTypeID('layerID')), 
      desc: desc
    } ;
    res.push(layerItem) ;
  }

  return res ;
}

Votes

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
Explorer ,
Feb 26, 2025 Feb 26, 2025

Copy link to clipboard

Copied

This is perfect, thanks for your time!

Votes

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
Community Expert ,
Feb 26, 2025 Feb 26, 2025

Copy link to clipboard

Copied

LATEST

@johnjoeparrot 

 

You will also find many examples by searching the forum with the keywords "selected layers”:

 

https://community.adobe.com/t5/forums/searchpage/tab/message?filter=location&q=selected%20layers&noS...

Votes

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