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

Rename Active Layer

Enthusiast ,
Nov 05, 2013 Nov 05, 2013

Copy link to clipboard

Copied

Hello, I have attempted this small script which will rename the active layer to a name of my choice which is written into the script. For example, when I run this script, I need it to rename the active layer to "My New Layer".

The script doesn't cause an error, but it doesn't rename the layer either. Might there be a way to do this?

function renameLayer() {

app.activeDocument.layers.rename("My New Layer");

}

TOPICS
Actions and scripting

Views

1.7K

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 Expert ,
Nov 05, 2013 Nov 05, 2013

Copy link to clipboard

Copied

var docRef = activeDocument;

docRef.activeLayer.name = "you're new name"

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
Community Expert ,
Nov 05, 2013 Nov 05, 2013

Copy link to clipboard

Copied

function renameLayer(layerName) {

             app.activeDocument.activeLayers.name=layerName;

}

If you want a script to use in an action to do interactively rename a targeted layer in an action because that is no longer possible since CS6 you could do the with a on liner that is a prompt.

app.activeDocument.activeLayer.name = prompt('Rename layer ' + app.activeDocument.activeLayer.name  + ' to ', ' ');

Or use a more complex script that insyres these is an targeted layer

* ==========================================================

// 2013  John J. McAssey (JJMack)

// ======================================================= */

// This script is supplied as is. It is provided as freeware.

// The author accepts no liability for any problems arising from its use.

// enable double-clicking from Mac Finder or Windows Explorer

#target photoshop // this command only works in Photoshop CS2 and higher

// bring application forward for double-click events

app.bringToFront();

// ensure at least one document open

if (!documents.length) alert('There are no documents open.', 'No Document');

else {

          var sLayers = getSelectedLayersIdx();

        if (sLayers.length == 1) {app.activeDocument.activeLayer.name = prompt('Rename layer ' + app.activeDocument.activeLayer.name  + ' to ', ' '); }

          else { alert("Check that you have  a single layer targeted"); }

}

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

//                              Helper Functions                                                  //

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

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" )));

         }

     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;

};

JJMack

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
Enthusiast ,
Nov 05, 2013 Nov 05, 2013

Copy link to clipboard

Copied

LATEST

thanks to both of you - both work great and are fast, too 

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