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
How to, Scripting

Views

54

Likes

translate

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

Adobe Community Professional , 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(/\.[^\.]*$/, "")...

Likes

translate

Translate

Translate
Adobe Community Professional ,
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

Likes

translate

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

It works. Thank you very much.

Likes

translate

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