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

Renaming Text In Selection

Participant ,
May 04, 2021 May 04, 2021
Hey All.  Its been a while but I am really struggling with this function.  This seems to work when I give the ActiveArtboardIndex a specific number, but when using a loop the text object will not change.  Can anyone give me some insite as to why this will only work with a specific number and not the loop input?
 
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'){
         idoc.selection[j].contents = artbs[i].name;
     }
  }
}
TOPICS
Performance , Scripting
1.9K
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

correct answers 1 Correct answer

Guide , May 04, 2021 May 04, 2021

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;
        }
    }
Translate
Adobe
Guide ,
May 04, 2021 May 04, 2021

All I can tell you is that it works fine for me.  What AI version are you using?  (selectObjectsOnActiveArtboard() is only available in CS6+.)

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
Participant ,
May 04, 2021 May 04, 2021

CC 25.01 2021 newest version.  

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 ,
May 04, 2021 May 04, 2021

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

 

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
Participant ,
May 04, 2021 May 04, 2021

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.

 

 

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 ,
May 04, 2021 May 04, 2021

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

 

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
Participant ,
May 04, 2021 May 04, 2021

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.

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 ,
May 04, 2021 May 04, 2021

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;
        }
    }
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
Participant ,
May 04, 2021 May 04, 2021
LATEST

Works!  Thanks F for the help.  Sometimes after looking at the same thing for an hour it takes another set of eyes.

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