replace specific name in layer in adobe illustrator

New Here ,
Jun 04, 2022 Jun 04, 2022

Copy link to clipboard

Copied

Hi,

I have really tried but can't really understand the illustrator script guide.

I want to rename my selected layer with the name "copyfx" but what changes are all layers

what's wrong with this script?

//

var document = app.activeDocument;
var layers= document.layers;

for(var i =0; i < layers.length;i++) {
layers[i].name ="copyfx";
}

 

Mgotchan5CE2_0-1654379586867.png

 

is there a way to solve it? thanks

 

TOPICS
How to , Scripting

Views

102

Likes

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
Advisor ,
Jun 04, 2022 Jun 04, 2022

Copy link to clipboard

Copied

The above script loops through all the layers and names each layer, as it is written to do. 

 

Layers don't have a "selected" property, but they do have a "hasSelectedArtwork" property.  One can add a conditional to test whether or not a layer "hasSelectedArtwork", limiting the naming to those layers which do.

 

var document = app.activeDocument;
var layers = document.layers;
for (var i = 0; i < layers.length; i++) {
    if (layers[i].hasSelectedArtwork == true) {
        layers[i].name = "copyfx";
    }
}

 

Likes

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
New Here ,
Jun 04, 2022 Jun 04, 2022

Copy link to clipboard

Copied

this works, but what I mean is renaming the active sublayer, is there a workaround?

Mgotchan5CE2_0-1654381033269.png

 

Likes

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
Advisor ,
Jun 04, 2022 Jun 04, 2022

Copy link to clipboard

Copied

There are no sublayers in the image.  There are layers and path items. This will name the active layer. 

 

var document = app.activeDocument;
document.activeLayer.name = "copyfx";

 

Likes

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
New Here ,
Jun 04, 2022 Jun 04, 2022

Copy link to clipboard

Copied

LATEST

is this script correct?
sorry I never code

Mgotchan5CE2_0-1654381954618.png

 

Likes

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