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

Text layer duplicate and update layer name

Engaged ,
Sep 26, 2024 Sep 26, 2024

Copy link to clipboard

Copied

So I've been having problems with duplicating text layers via scripts. In that the layer names are not automatically updating when the text content is changed.

 

  if (app.activeDocument.activeLayer.kind == LayerKind.TEXT)
  {
    // duplicate text
    var idCpTL = charIDToTypeID( "CpTL" );
    executeAction( idCpTL, undefined, DialogModes.NO );
  }
  else
  {
    //. .. duplicate layer in prefered way...

  }

 

Just thought I'd share the joy.

TOPICS
Actions and scripting

Views

62

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
LEGEND ,
Sep 26, 2024 Sep 26, 2024

Copy link to clipboard

Copied

I wrote this for my own use, because data-driven graphics text layers are just generically named and it was a problem. Apache licensed, feel free to modify it. I strip out return characters in the layerText.

 

/*
Utility Pack Scripts created by David M. Converse ©2018-24

This script renames text layers in an open Photoshop document

Last modifed 7/5/2024

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
#target photoshop

renameTextLayers();

function renameTextLayers(){
    if(!app.documents.length > 0){
        return;
        }
    var docRef = null;
    var vis = true;
    var LayerRef = null;
    var TextRef = null;
    var layerText = '';
    try{
        docRef = app.activeDocument;
        docRef.activeLayer = docRef.artLayers[0];
        for(var i = 0; i < docRef.artLayers.length; i++){
            LayerRef = docRef.artLayers[i];
            vis = true;
            if(LayerRef.kind == LayerKind.TEXT){
                if(!LayerRef.visible){
                    vis = false;
                    }
                TextRef = LayerRef.textItem;
                layerText = TextRef.contents;
                layerText = layerText.replace(/\r$/, '');
                layerText = layerText.replace(/,\r/, ', ');
                if(layerText.search('\r') == -1){
                    layerText = layerText.split(' ');
                    layerText[0] = layerText[0].replace(',', '');
                    }
                else{
                    layerText = layerText.split('\r');
                    }
                LayerRef.name = layerText[0];
                if(vis == false){
                    LayerRef.visible = false;
                    }
                }
            }
        }
    catch(e){
        Window.alert(e + e.line);
        }
    }

 

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 ,
Sep 27, 2024 Sep 27, 2024

Copy link to clipboard

Copied

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
Engaged ,
Sep 27, 2024 Sep 27, 2024

Copy link to clipboard

Copied

LATEST

Funily enough I did. The enter, backspace, enter "solution" didn't work for me. So I made my own and thought it worth sharing.

 

 

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