Copy link to clipboard
Copied
Copy link to clipboard
Copied
All I can tell you is that it works fine for me. What AI version are you using? (selectObjectsOnActiveArtboard() is only available in CS6+.)
Copy link to clipboard
Copied
CC 25.01 2021 newest version.
Copy link to clipboard
Copied
Do you get an alert for each artboard?
var idoc = activeDocument;
var artbs = idoc.artboards;
for (var i = artbs.length-1 ; i >= 0; i--) {
idoc.selection = null;
artbs.setActiveArtboardIndex(i);
idoc.selectObjectsOnActiveArtboard();
if (selection.length > 0) {
alert(i);
}
}
Copy link to clipboard
Copied
Yes. I get alerts for each artboard as well as each TextFrame. Just reset my machine as well to make sure its not a cache issue. Still no go. Looks like its totally jumping over the if statement to change by textFrame.
Copy link to clipboard
Copied
Do you get an alert for each "ABR"?
var idoc = activeDocument;
var artbs = idoc.artboards;
for (var i = artbs.length-1 ; i >= 0; i--) {
idoc.selection = null;
artbs.setActiveArtboardIndex(i);
idoc.selectObjectsOnActiveArtboard();
for(var j = 0; j < idoc.selection.length; j++){
if (idoc.selection[j].typename == "TextFrame" && idoc.selection[j].contents == 'ABR'){
alert(i);
}
}
}
Copy link to clipboard
Copied
Figured out! The text can not be grouped with another object. Otherwise it can not find it. Still not sure why it works when specing a specific artboard, but I have it working now.
Copy link to clipboard
Copied
If your selection is a groupItem, your idoc.selection[j].typename is "GroupItem" and your conditional will not be met. You could change your inner loop to
for (var j = 0; j < idoc.textFrames.length; j++){
if (idoc.textFrames[j].selected == true && idoc.textFrames[j].contents == "ABR") {
idoc.textFrames[j].contents = artbs[i].name;
}
}
Copy link to clipboard
Copied
Works! Thanks F for the help. Sometimes after looking at the same thing for an hour it takes another set of eyes.