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

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

New Here ,
Jun 11, 2018 Jun 11, 2018

Copy link to clipboard

Copied

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~ 

TOPICS
Actions and scripting

Views

1.9K

Translate

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

Guide , Jun 11, 2018 Jun 11, 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" ) );

...

Votes

Translate

Translate
Adobe
Guide ,
Jun 11, 2018 Jun 11, 2018

Copy link to clipboard

Copied

activeLayer means ONE layer only!

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

Votes

Translate

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
New Here ,
Jun 11, 2018 Jun 11, 2018

Copy link to clipboard

Copied

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.

Votes

Translate

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
Guide ,
Jun 11, 2018 Jun 11, 2018

Copy link to clipboard

Copied

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

};

Votes

Translate

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
New Here ,
Jun 11, 2018 Jun 11, 2018

Copy link to clipboard

Copied

Thank  you, got it!

Votes

Translate

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 ,
Jun 12, 2018 Jun 12, 2018

Copy link to clipboard

Copied

LATEST

To select several layers with code I use this function, where the layer-IDs to be selected are stored in an array.

// layers to be selected (convert layer index to id:

id1 = getLayerId(activeDocument.layers[0])  //

id2 = getLayerId(activeDocument.layers[2])

// add more IDs if wanted

// store the layer-IDs into an array:

ary = [id1, id2]

// call the function

ret = selectLyr()

function selectLyr(lyrAry) {

    ////////////////////////////////////////////////////////

    // Description: Selects multiple layers

    // Parameters: lyrAry (Array):  Contains the layer-IDs to be  selected

    //  Return: boolean

    ////////////////////////////////////////////////////////

   

    if (lyrAry==undefined || lyrAry.constructor != Array )  return  false

    var d = new ActionDescriptor();

    var r = new ActionReference();

    for (var i = 0; i < lyrAry.length; i++) {       

        r.putIdentifier( s2t( "layer" ), lyrAry ) ;                         // Array of layer by ID

    }

                                                           

    d.putReference( c2t( "null" ), r );

    d.putEnumerated( s2t( "selectionModifier" ), s2t( "selectionModifierType" ), s2t(  "addToSelection") );

    d.putBoolean( s2t( "makeVisible" ), true );

    try {executeAction( s2t( "select" ), d, DialogModes.NO ); return true;}

    catch(e) { return false }

}

function getLayerId(theLayer){

    // by mike hale, via paul riggott;

    // http://forums.adobe.com/message/1944754#1944754

    app.activeDocument.activeLayer = theLayer;      // theLayer must be object

    //Assumes activeDocument and activeLayer  

    var r = new ActionReference();

    r.putEnumerated(c2t("Lyr "), c2t("Ordn"), c2t("Trgt"));

    d = executeActionGet(r);

    return d.getInteger( c2t('LyrI') );

};

function c2t (s) {return app.charIDToTypeID(s)};

function s2t (s) {return app.stringIDToTypeID(s)};

Votes

Translate

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
New Here ,
Jun 11, 2018 Jun 11, 2018

Copy link to clipboard

Copied

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 .

Votes

Translate

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