7 Replies Latest reply on Mar 17, 2013 4:41 AM by Paul Riggott

    How to disable auto rename text layer with content

    kenrou123

      HI Every one,

       

      I want to disable the auto renaming feature in text layers so that I can change the content without change the name of the text layer.

       

      also i want to do this to all the text in one step, wthout do it manual one by one.

       

      for more description, i am working on replace English text with other language but i want to keep English name of all text layers SO i want to disable auto renaming while replacing the content.

       

      I guess a Script could do this by changing the names (adding a space or a _ for example)

       

       

      Thanks in advance

       


        

        • 1. Re: How to disable auto rename text layer with content
          Michael L Hale Level 5

          You don't need to add a prefix/suffix to the layer name. All you have to do is name the layer. Photoshop by default names a text layer with at least part of the text contents. When the contents is changed Photohop updates the layer name. To stop the auto-updating of the layer name you just need to name the layer. Photoshop will not update a named layer.

           

          Are any of the text layers in layerSets? The code are looping layers is different if there are layerSets in the document.

          • 2. Re: How to disable auto rename text layer with content
            kenrou123 Level 1

            Dear Michael

             

            Thanks for your advice but i need to do this in all the text layers in one step, I have 50+ test layer I want to stop the update process and keep the name of the text layer the same.

            • 3. Re: How to disable auto rename text layer with content
              Michael L Hale Level 5

              kenrou123 wrote:

               

              Thanks for your advice but i need to do this in all the text layers in one step

              I understood that which is why I asked if the layers were in layerSets. I need to know more about how the document is setup before I post any code to rename the layers.

              • 4. Re: How to disable auto rename text layer with content
                kenrou123 Level 1

                Yes I have some of the text layers in layerSets and some without layerSets

                 

                Thanks in advance

                • 5. Re: How to disable auto rename text layer with content
                  Paul Riggott Level 6

                  This should add a space after the layer name...

                   

                   

                  main();
                  function main(){
                  if(!documents.length) return;
                  var txtLayers = getNamesPlusIDs();
                  for (var a in txtLayers){
                      putLayerNameByID(Number(txtLayers[a][0]),(txtLayers[a][1].toString()+' '));
                      }
                  }
                  function putLayerNameByID( ID, name ) {
                  var desc = new ActionDescriptor();
                  var ref = new ActionReference();
                  ref.putIdentifier( charIDToTypeID('Lyr '), ID );
                  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 );
                  }
                  function getNamesPlusIDs(){ 
                     var ref = new ActionReference(); 
                     ref.putEnumerated( charIDToTypeID('Dcmn'), charIDToTypeID('Ordn'), charIDToTypeID('Trgt') ); 
                     var count = executeActionGet(ref).getInteger(charIDToTypeID('NmbL')) +1; 
                     var Names=[];
                  try{
                      activeDocument.backgroundLayer;
                  var i = 0; }catch(e){ var i = 1; };
                     for(i;i<count;i++){ 
                         if(i == 0) continue;
                          ref = new ActionReference(); 
                          ref.putIndex( charIDToTypeID( 'Lyr ' ), i );
                          var desc = executeActionGet(ref);
                          var layerName = desc.getString(charIDToTypeID( 'Nm  ' ));
                          var Id = desc.getInteger(stringIDToTypeID( 'layerID' ));
                          if(layerName.match(/^<\/Layer group/) ) continue;
                          var layerType = typeIDToStringID(desc.getEnumerationValue( stringIDToTypeID( 'layerSection' )));
                          var isLayerSet =( layerType == 'layerSectionContent') ? false:true;
                          if(desc.hasKey( stringIDToTypeID( 'textKey' ) ) ) Names.push([[Id],[layerName]]);
                     }; 
                  return Names;
                  };
                  
                  
                  • 6. Re: How to disable auto rename text layer with content
                    kenrou123 Level 1

                    Dear Paul

                     

                    Thanks for you work

                     

                    your script works very good but I need to remove the space again from all the text layers so that the text layer name remain in its original name without space.

                     

                    That because I use another script require the text layer name to be the same.

                    • 7. Re: How to disable auto rename text layer with content
                      Paul Riggott Level 6

                      You could change line 6 from...

                       

                      putLayerNameByID(Number(txtLayers[a][0]),(txtLayers[a][1].toString()+' '));
                      

                       

                      To...

                       

                      putLayerNameByID(Number(txtLayers[a][0]),(txtLayers[a][1].toString().replace(/\s$/,'')));
                      

                       

                      This will remove the space at the end of the layers name.

                       

                       

                      For future use on different files.

                       

                      Change that line again so it is setting the name as the name with...

                       

                      putLayerNameByID(Number(txtLayers[a][0]),(txtLayers[a][1].toString()));