Find and rename all textFrames having the same name

Contributor ,
Jun 15, 2022 Jun 15, 2022

Copy link to clipboard

Copied

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

 

 

TOPICS
Scripting

Views

57

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

correct answers 1 Correct answer

Adobe Community Professional , Jun 15, 2022 Jun 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.

Likes

Translate

Translate
Advisor ,
Jun 15, 2022 Jun 15, 2022

Copy link to clipboard

Copied

You are looping through textFrames, not pathItems.

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
Contributor ,
Jun 15, 2022 Jun 15, 2022

Copy link to clipboard

Copied

Sorry!
I mean textFrames

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
Adobe Community Professional ,
Jun 15, 2022 Jun 15, 2022

Copy link to clipboard

Copied

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

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
Adobe Community Professional ,
Jun 15, 2022 Jun 15, 2022

Copy link to clipboard

Copied

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

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
Contributor ,
Jun 15, 2022 Jun 15, 2022

Copy link to clipboard

Copied

LATEST

Working great, thank you!

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