Welcome Dialog

Welcome to the Community!

We have a brand new look! Take a tour with us and explore the latest updates on Adobe Support Community.


Renaming Text In Selection

Participant ,
May 04, 2021 May 04, 2021

Copy link to clipboard

Copied

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

Views

841

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

Advocate , 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; } }

Likes

Translate

Translate
Advocate ,
May 04, 2021 May 04, 2021

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+.)

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

Copy link to clipboard

Copied

CC 25.01 2021 newest version.  

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

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

 

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

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.

 

 

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

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

 

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

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.

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

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

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

Copy link to clipboard

Copied

LATEST

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

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