What's new
Photoshop Gurus Forum

Welcome to Photoshop Gurus forum. Register a free account today to become a member! It's completely free. Once signed in, you'll enjoy an ad-free experience and be able to participate on this site by adding your own topics and posts, as well as connect with other members through your own private inbox!

Reply to thread

What you can do is run this script twice, the first time to copy the layer name. You would then have to select the layer(s) to want to rename then run the script again to do the rename(s).

[code]

#target photoshop

main();

function main(){

if(!documents.length) return;

if ($.getenv("lName") == null){

    var test = getSelectedLayersIdx();

    if(test.length > 1) {

        alert("Only ONE layer should be selected!");

        return;

        }

    $.setenv("lName", activeDocument.activeLayer.name);

    return;

    }

var selected = getSelectedLayersIdx();

for(var a in selected){

    putLayerNameByIndex(Number(selected[a]),$.getenv("lName"));

    }

    $.setenv("lName","");

};

function getSelectedLayersIdx(){

      var selectedLayers = new Array();

      var backGroundCounter = 1;

            if(activeDocument.artLayers.length > 0){

            backGroundCounter = activeDocument.artLayers[activeDocument.artLayers.length - 1].isBackgroundLayer ? 0 : 1;

            }

      var ref = new ActionReference();

      ref.putProperty(charIDToTypeID("Prpr"), stringIDToTypeID("targetLayers"));

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

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

          }

      if(app.version.match(/^\d+/) > 15) return selectedLayers ;

       }else{

         var ref = new ActionReference();

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

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

         if(!backGroundCounter){

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

            }else{

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

                }

     var vis = app.activeDocument.activeLayer.visible;

        if(vis == true) app.activeDocument.activeLayer.visible = false;

        var desc9 = new ActionDescriptor();

    var list9 = new ActionList();

    var ref9 = new ActionReference();

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

    list9.putReference( ref9 );

    desc9.putList( charIDToTypeID("null"), list9 );

    executeAction( charIDToTypeID("Shw "), desc9, DialogModes.NO );

    if(app.activeDocument.activeLayer.visible == false) selectedLayers.shift();

        app.activeDocument.activeLayer.visible = vis;

      }

      return selectedLayers;

};

function putLayerNameByIndex( idx, name ) {

     if( idx == 0 ) return;

    var desc = new ActionDescriptor();

        var ref = new ActionReference();

        ref.putIndex( charIDToTypeID( 'Lyr ' ), idx );

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

        var nameDesc = new ActionDescriptor();

        nameDesc.putString( charIDToTypeID('Nm  '), name );

    desc.putObject( charIDToTypeID('T   '), charIDToTypeID('Lyr '), nameDesc );

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

    executeAction( charIDToTypeID('setd'), desc, DialogModes.NO );

};

[/code]


What is our favorite program/app? (Hint - it begins and ends with the letter P)
Back
Top