Welcome Dialog

Welcome to the Community!

We have a brand new look! Take a tour with us and explore the latest updates on Adobe Support Community.


Apply an action to all selected layers

Explorer ,
Mar 03, 2017 Mar 03, 2017

Copy link to clipboard

Copied

Hy!

I wish to do an action i 've made (select a specific zone and deleted it), on every layer i selected.

It can be 2 to 28 layers...

I hope you can help me

THX

TOPICS
Actions and scripting

Views

9.6K

Likes

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 , Mar 03, 2017 Mar 03, 2017

Likes

Translate

Translate
Guide ,
Mar 03, 2017 Mar 03, 2017

Copy link to clipboard

Copied

Likes

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 ,
Mar 17, 2017 Mar 17, 2017

Copy link to clipboard

Copied

Hi WonderMerlin

OK, i wish to scale all my layers to a selection, do you have an issue for this?

Likes

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 ,
Mar 17, 2017 Mar 17, 2017

Copy link to clipboard

Copied

i write this

#target photoshop

if (app.documents.length > 0) {

var myDocument = app.activeDocument;

myDocument.suspendHistory("operation", "main(myDocument)");

};

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

function main () {

var theLayers = getSelectedLayersIdx();

// do stuff;

// reselect layers;

for (var p = 0; p < theLayers.length; p++) {

  selectLayerByIndex(theLayers

, false);

  app.doAction('Scale layer to select', 'SHOES MODIF TAILLE');// ici defi l'action pour les layers selectiones

  };

};

//

function selectLayerByIndex(index,add){

add = undefined ? add = false: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){

alert(e.message);

}

};

////// by paul mr;

function getSelectedLayersIdx(){

      var selectedLayers = new Array;

      var ref = new ActionReference();

      ref.putEnumerated( charIDToTypeID("Dcmn"), charIDToTypeID("Ordn"), charIDToTypeID("Trgt") );

      var desc = executeActionGet(ref);

      if( desc.hasKey( stringIDToTypeID( 'targetLayers' ) ) ){

         desc = desc.getList( stringIDToTypeID( 'targetLayers' ));

          var c = desc.count

          var selectedLayers = new Array();

          for(var i=0;i<c;i++){

            try{

               activeDocument.backgroundLayer;

               selectedLayers.push(  desc.getReference( i ).getIndex() );

            }catch(e){

               selectedLayers.push(  desc.getReference( i ).getIndex()+1 );

            }

          }

       }else{

         var ref = new ActionReference();

         ref.putProperty( charIDToTypeID("Prpr") , charIDToTypeID( "ItmI" ));

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

         try{

            activeDocument.backgroundLayer;

            selectedLayers.push( executeActionGet(ref).getInteger(charIDToTypeID( "ItmI" ))-1);

         }catch(e){

            selectedLayers.push( executeActionGet(ref).getInteger(charIDToTypeID( "ItmI" )));

         }

      }

      return selectedLayers;

};

Likes

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 ,
Mar 17, 2017 Mar 17, 2017

Copy link to clipboard

Copied

#target photoshop

if (app.documents.length > 0) {

var myDocument = app.activeDocument;

myDocument.suspendHistory("operation", "main(myDocument)");

};

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

function main () {

var theLayers = getSelectedLayersIdx();

// do stuff;

// reselect layers;

for (var p = 0; p < theLayers.length; p++) {

  selectLayerByIndex(theLayers

, false);

  app.doAction('Scale layer to select', 'SHOES MODIF TAILLE');// ici defi l'action pour les layers selectiones

  };

};

//

function selectLayerByIndex(index,add){

add = undefined ? add = false: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){

alert(e.message);

}

};

////// by paul mr;

function getSelectedLayersIdx(){

      var selectedLayers = new Array;

      var ref = new ActionReference();

      ref.putEnumerated( charIDToTypeID("Dcmn"), charIDToTypeID("Ordn"), charIDToTypeID("Trgt") );

      var desc = executeActionGet(ref);

      if( desc.hasKey( stringIDToTypeID( 'targetLayers' ) ) ){

         desc = desc.getList( stringIDToTypeID( 'targetLayers' ));

          var c = desc.count

          var selectedLayers = new Array();

          for(var i=0;i<c;i++){

            try{

               activeDocument.backgroundLayer;

               selectedLayers.push(  desc.getReference( i ).getIndex() );

            }catch(e){

               selectedLayers.push(  desc.getReference( i ).getIndex()+1 );

            }

          }

       }else{

         var ref = new ActionReference();

         ref.putProperty( charIDToTypeID("Prpr") , charIDToTypeID( "ItmI" ));

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

         try{

            activeDocument.backgroundLayer;

            selectedLayers.push( executeActionGet(ref).getInteger(charIDToTypeID( "ItmI" ))-1);

         }catch(e){

            selectedLayers.push( executeActionGet(ref).getInteger(charIDToTypeID( "ItmI" )));

         }

      }

      return selectedLayers;

};

Likes

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
Adobe Community Professional ,
May 31, 2018 May 31, 2018

Copy link to clipboard

Copied

Thank you for sharing!

 

(For those new to scripting, It is all about editing line 13 to reference the loaded action name and action set name.

 

A similar recent topic thread here:

 

Is there a way to resize the height of multiple images at once without setting a specific width?

Likes

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 ,
Sep 13, 2021 Sep 13, 2021

Copy link to clipboard

Copied

do you mean line 113?

 

Likes

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
Adobe Community Professional ,
Sep 13, 2021 Sep 13, 2021

Copy link to clipboard

Copied

LATEST

No, line 13 in the original post from showshow in 2017... The forum software has gone through a number of changes over time and old code is not always the same when viewed today:

 

app.doAction('Scale layer to select', 'SHOES MODIF TAILLE');// ici defi l'action pour les layers selectiones

 

Likes

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 ,
May 31, 2018 May 31, 2018

Copy link to clipboard

Copied

your script is amazing, thank you so much!!

Likes

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 ,
Mar 03, 2017 Mar 03, 2017

Copy link to clipboard

Copied

It's sublime,

Likes

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
Community Beginner ,
Feb 22, 2018 Feb 22, 2018

Copy link to clipboard

Copied

I'm very surprised there is still no native concized way to check if a layer is selected or not, seems pretty essential function for a majority of layer related scripts.

It should be a layer property IMHO, or at least there should be a IsLayerSelected(layer) function (or alternative getter/setter).

Likes

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