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

Script to select multiple layers

Community Expert ,
Oct 11, 2019 Oct 11, 2019

I used to have a script that would select multiple layers by ID, but can't find it, and the old forum post are gone. Does anyone have a script that will do that? Thanks

TOPICS
Actions and scripting
5.7K
Translate
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 3 Correct answers

Advocate , Oct 11, 2019 Oct 11, 2019

See if this is good for you

the code was entered by r-bin

 

select_layer("layer 2");

select_layer("layer 1", true);

function select_layer(nm, add)

    {   

    try {

        var r = new ActionReference();

        r.putName(stringIDToTypeID("layer"), nm);

        var d = new ActionDescriptor();

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

        if (add == true) d.putEnumerated(stringIDToTypeID("selectionModifier"), stringIDToTypeID("selectionModifierType"), stringIDToTypeID("addTo
...
Translate
Community Expert , Oct 11, 2019 Oct 11, 2019

////// based on code by mike hale and paul riggott //////

function selectLayerByID(index,add){ 

add = undefined ? add = false:add 

var ref = new ActionReference();

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

    var desc = new ActionDescriptor();

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

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

      desc.putBoolean( charIDToTypeI

...
Translate
Community Expert , Oct 11, 2019 Oct 11, 2019

Thanks, everyone. I actually finally found what I was looking for. It takes an array of layer ids and selects the layer.:

function doesIdExists( id ){// function to check if the id exists
   var res = true;
   var ref = new ActionReference();
   ref.putIdentifier(charIDToTypeID('Lyr '), id);
    try{var desc = executeActionGet(ref)}catch(err){res = false};
    return res;
}

function multiSelectByIDs(ids) {
  if( ids.constructor != Array ) ids = [ ids ];
    var layers = new Array();
    var id5
...
Translate
Adobe
Community Expert ,
Oct 11, 2019 Oct 11, 2019
Translate
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 ,
Oct 11, 2019 Oct 11, 2019

I thought by ID you meant InDesign, sorry ignore my post.

Translate
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 ,
Oct 11, 2019 Oct 11, 2019
Thanks anyway!
Translate
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
Advocate ,
Oct 11, 2019 Oct 11, 2019

See if this is good for you

the code was entered by r-bin

 

select_layer("layer 2");

select_layer("layer 1", true);

function select_layer(nm, add)

    {   

    try {

        var r = new ActionReference();

        r.putName(stringIDToTypeID("layer"), nm);

        var d = new ActionDescriptor();

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

        if (add == true) d.putEnumerated(stringIDToTypeID("selectionModifier"), stringIDToTypeID("selectionModifierType"), stringIDToTypeID("addToSelection"));

        executeAction(stringIDToTypeID("select"), d, DialogModes.NO);

        }

    catch (e) { alert(e); throw(e); }

    }

 

Translate
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 ,
Oct 11, 2019 Oct 11, 2019

////// based on code by mike hale and paul riggott //////

function selectLayerByID(index,add){ 

add = undefined ? add = false:add 

var ref = new ActionReference();

    ref.putIdentifier(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){

alert(e.message); 

}

};

Translate
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 ,
Oct 11, 2019 Oct 11, 2019
LATEST

Thanks, everyone. I actually finally found what I was looking for. It takes an array of layer ids and selects the layer.:

function doesIdExists( id ){// function to check if the id exists
   var res = true;
   var ref = new ActionReference();
   ref.putIdentifier(charIDToTypeID('Lyr '), id);
    try{var desc = executeActionGet(ref)}catch(err){res = false};
    return res;
}

function multiSelectByIDs(ids) {
  if( ids.constructor != Array ) ids = [ ids ];
    var layers = new Array();
    var id54 = charIDToTypeID( "slct" );
    var desc12 = new ActionDescriptor();
    var id55 = charIDToTypeID( "null" );
    var ref9 = new ActionReference();
    for (var i = 0; i < ids.length; i++) {
       if(doesIdExists(ids[i]) == true){// a check to see if the id stil exists
           layers[i] = charIDToTypeID( "Lyr " );
           ref9.putIdentifier(layers[i], ids[i]);
       }
    }
    desc12.putReference( id55, ref9 );
    var id58 = charIDToTypeID( "MkVs" );
    desc12.putBoolean( id58, false );
    executeAction( id54, desc12, DialogModes.NO );
}

.

Translate
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