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

I want to make a script that renames layer with the linked file name

Community Beginner ,
Mar 17, 2021 Mar 17, 2021

Copy link to clipboard

Copied

DjordjeSS_0-1615991406613.png

So as you can see I want it to change layer 8 to Pets-simbolos-2

 

I have tried to write something but it doesn't work, I am new to the scripts.

 

function test()

{

//var Sel_itemPlaced = app.activeDocument.placedItems[0]; // if nothing is selected - use the first linked file item

var sel_itemPlaced = app.activeDocument.selection[0]; // be sure that a linked item (and not an embedded) is selected

var selPos = sel_itemPlaced.position;

var aTF = app.activeDocument.textFrames.add();

var fileName = sel_itemPlaced.file.name;

var textContents = fileName.replace(/\%20/g," "); //change %20 to spaces

textContents = textContents.replace(/\.[^\.]*$/,""); //remove extension

 

for (var i = 0; i < layers.length; i++) {

layers.name = textContents;
}
}
test();

 

I've also tried to find at least one script that allows me to copy the name in the clipboard, at least that will help me a bit, but no luck.

TOPICS
Scripting

Views

222

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

Community Expert , Mar 17, 2021 Mar 17, 2021

Hi,

Try follwoing snippet. Before you run the script make sure to select the linked file in the document. The following script will rename parent layer of the selected linked item.

function test() {
    var sel_itemPlaced = app.activeDocument.selection[0]; // be sure that a linked item (and not an embedded) is selected
    var fileName = sel_itemPlaced.file.name;
    var textContents = fileName.replace(/\%20/g, " "); //change %20 to spaces
    textContents = textContents.replace(/\.[^\.]*$/, "")
...

Votes

Translate

Translate
Adobe
Community Expert ,
Mar 17, 2021 Mar 17, 2021

Copy link to clipboard

Copied

Hi,

Try follwoing snippet. Before you run the script make sure to select the linked file in the document. The following script will rename parent layer of the selected linked item.

function test() {
    var sel_itemPlaced = app.activeDocument.selection[0]; // be sure that a linked item (and not an embedded) is selected
    var fileName = sel_itemPlaced.file.name;
    var textContents = fileName.replace(/\%20/g, " "); //change %20 to spaces
    textContents = textContents.replace(/\.[^\.]*$/, ""); //remove extension
    var _item = sel_itemPlaced;
    while (_item.parent.typename != 'Layer') {
        _item = _item.parent;
    }
    _item.parent.name = textContents;
}
test();
Best regards

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 Beginner ,
Mar 17, 2021 Mar 17, 2021

Copy link to clipboard

Copied

LATEST

It works. Thank you very much.

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