Skip to main content
Inspiring
June 15, 2022
Answered

Find and rename all textFrames having the same name

  • June 15, 2022
  • 2 replies
  • 490 views

Hi,

At activedocument there is multiple textFrames named "Text"

I want to rename each one  to Text0, Text1, Text2

This is not wotking

 

#target illustrator
var SearchName = "Text";
var count = 0;
var textObjects = app.activeDocument.textFrames
for (var i = 0; i < textObjects.length; i++) {
if (textObjects[i].getByName(SearchName) {
textObjects[i].name = SearchName + count ;
 count ++;
}
}

 

 

This topic has been closed for replies.
Correct answer Charu Rajput

Hell, Try following

 

#target illustrator

var SearchName = "Text";
var count = 0;
var textObjects = app.activeDocument.textFrames
for (var i = 0; i < textObjects.length; i++) {
    if (textObjects[i].name == SearchName) {
        textObjects[i].name = SearchName + count;
        count++;
    }
}

Error in in your versions:
1. Round bracket missing in if statement

2. You are using the getByName on each textFrame like textFrame[i], instead it should be textFrames.getByNamewithout i.

 

2 replies

Charu Rajput
Community Expert
Charu RajputCommunity ExpertCorrect answer
Community Expert
June 15, 2022

Hell, Try following

 

#target illustrator

var SearchName = "Text";
var count = 0;
var textObjects = app.activeDocument.textFrames
for (var i = 0; i < textObjects.length; i++) {
    if (textObjects[i].name == SearchName) {
        textObjects[i].name = SearchName + count;
        count++;
    }
}

Error in in your versions:
1. Round bracket missing in if statement

2. You are using the getByName on each textFrame like textFrame[i], instead it should be textFrames.getByNamewithout i.

 

Best regards
Charu Rajput
Community Expert
Community Expert
June 15, 2022

Another version of script using with the getByName

#target illustrator

var SearchName = "Text";
var count = 0;
var textObjects = app.activeDocument.textFrames
for (var i = 0; i < textObjects.length; i++) {
    try {
        if (textObjects.getByName(SearchName)) {
            textObjects[i].name = SearchName + count;
            count++;
        }
    } catch (e) { }
}
Best regards
femkeblanco
Legend
June 15, 2022

You are looping through textFrames, not pathItems.

siomospAuthor
Inspiring
June 15, 2022

Sorry!
I mean textFrames