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 ++;
}
}
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.
Copy link to clipboard
Copied
You are looping through textFrames, not pathItems.
Copy link to clipboard
Copied
Sorry!
I mean textFrames
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.
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) { }
}
Copy link to clipboard
Copied
Working great, thank you!