Skip to main content
Participant
June 11, 2018
Answered

How to set several artLayers as activeLayer at the same time?

  • June 11, 2018
  • 2 replies
  • 2254 views

Now I know several artLayers,and I want to set them as activeLayer at the same time. But one artLayer can be set as activeLayer when I use app.activeDocument.activeLayer

help~help~help~ 

This topic has been closed for replies.
Correct answer SuperMerlin

You can select layers by Index , Id or by Name

Or select all layers.

Here are some functions that will let you do all the options including the merge.

function selectLayerByIndex(index,add){

var ref = new ActionReference();

ref.putIndex(charIDToTypeID("Lyr "), index);

var desc = new ActionDescriptor();

desc.putReference(charIDToTypeID("null"), ref );

if(add) desc.putEnumerated( stringIDToTypeID( "selectionModifier" ), stringIDToTypeID( "selectionModifierType" ), stringIDToTypeID( "addToSelection" ) );

desc.putBoolean( charIDToTypeID( "MkVs" ), false );

try{

executeAction(charIDToTypeID("slct"), desc, DialogModes.NO );

}catch(e){}

};

function selectLayerById(id,add){

var ref = new ActionReference();

ref.putIdentifier(charIDToTypeID("Lyr "), id);

var desc = new ActionDescriptor();

desc.putReference(charIDToTypeID("null"), ref );

if(add) desc.putEnumerated( stringIDToTypeID( "selectionModifier" ), stringIDToTypeID( "selectionModifierType" ), stringIDToTypeID( "addToSelection" ) );

desc.putBoolean( charIDToTypeID( "MkVs" ), false );

try{

executeAction(charIDToTypeID("slct"), desc, DialogModes.NO );

}catch(e){}

};

function selectLayerByName(lyrName,add){

add = undefined ? add = false:add

var desc = new ActionDescriptor();

var ref = new ActionReference();

ref.putName( charIDToTypeID( "Lyr " ), lyrName);

desc.putReference( charIDToTypeID( "null" ), ref );

if(add) desc.putEnumerated( stringIDToTypeID( "selectionModifier" ), stringIDToTypeID( "selectionModifierType" ), stringIDToTypeID( "addToSelection" ) );

desc.putBoolean( charIDToTypeID( "MkVs" ), false );

executeAction( charIDToTypeID( "slct" ), desc, DialogModes.NO );

};

function selectAllLayers() {

var desc29 = new ActionDescriptor();

var ref23 = new ActionReference();

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

desc29.putReference( charIDToTypeID("null"), ref23 );

executeAction( stringIDToTypeID("selectAllLayers"), desc29, DialogModes.NO );

};

function mergeSelected() {

try{

executeAction( charIDToTypeID('Mrg2'), undefined, DialogModes.NO );

}catch(e){}

};

2 replies

CurvinAuthor
Participant
June 11, 2018

As we all know, we can select several layers in the PS panel, but can we select several layers with code?

And now I have gotten several layers .

SuperMerlin
Inspiring
June 11, 2018

activeLayer means ONE layer only!

You can have several layers selected  but activeDocument.activeLayer will return details of the top most selected layer.

CurvinAuthor
Participant
June 11, 2018

SuperMerlin, Thank you for your reply!

So we can not select several layers with code? Now I want to select several layers and merge them with code.

CurvinAuthor
Participant
June 12, 2018

You can select layers by Index , Id or by Name

Or select all layers.

Here are some functions that will let you do all the options including the merge.

function selectLayerByIndex(index,add){

var ref = new ActionReference();

ref.putIndex(charIDToTypeID("Lyr "), index);

var desc = new ActionDescriptor();

desc.putReference(charIDToTypeID("null"), ref );

if(add) desc.putEnumerated( stringIDToTypeID( "selectionModifier" ), stringIDToTypeID( "selectionModifierType" ), stringIDToTypeID( "addToSelection" ) );

desc.putBoolean( charIDToTypeID( "MkVs" ), false );

try{

executeAction(charIDToTypeID("slct"), desc, DialogModes.NO );

}catch(e){}

};

function selectLayerById(id,add){

var ref = new ActionReference();

ref.putIdentifier(charIDToTypeID("Lyr "), id);

var desc = new ActionDescriptor();

desc.putReference(charIDToTypeID("null"), ref );

if(add) desc.putEnumerated( stringIDToTypeID( "selectionModifier" ), stringIDToTypeID( "selectionModifierType" ), stringIDToTypeID( "addToSelection" ) );

desc.putBoolean( charIDToTypeID( "MkVs" ), false );

try{

executeAction(charIDToTypeID("slct"), desc, DialogModes.NO );

}catch(e){}

};

function selectLayerByName(lyrName,add){

add = undefined ? add = false:add

var desc = new ActionDescriptor();

var ref = new ActionReference();

ref.putName( charIDToTypeID( "Lyr " ), lyrName);

desc.putReference( charIDToTypeID( "null" ), ref );

if(add) desc.putEnumerated( stringIDToTypeID( "selectionModifier" ), stringIDToTypeID( "selectionModifierType" ), stringIDToTypeID( "addToSelection" ) );

desc.putBoolean( charIDToTypeID( "MkVs" ), false );

executeAction( charIDToTypeID( "slct" ), desc, DialogModes.NO );

};

function selectAllLayers() {

var desc29 = new ActionDescriptor();

var ref23 = new ActionReference();

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

desc29.putReference( charIDToTypeID("null"), ref23 );

executeAction( stringIDToTypeID("selectAllLayers"), desc29, DialogModes.NO );

};

function mergeSelected() {

try{

executeAction( charIDToTypeID('Mrg2'), undefined, DialogModes.NO );

}catch(e){}

};


Thank  you, got it!