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

replace specific name in layer in adobe illustrator

New Here ,
Jun 04, 2022 Jun 04, 2022

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
Scripting
269
Translate
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
Guide ,
Jun 04, 2022 Jun 04, 2022

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";
    }
}

 

Translate
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

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

Mgotchan5CE2_0-1654381033269.png

 

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

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";

 

Translate
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
LATEST

is this script correct?
sorry I never code

Mgotchan5CE2_0-1654381954618.png

 

Translate
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