Back

If your email is not recognized and you believe it should be, please contact us.

  • You must be logged in to reply to this topic.Login

Assign script label based on textFrame contents

Return to Member Forum

  • Author
    Posts
    • #63676
      rjcjr
      Member

      I am trying to assign a specific script label to a textFrame, based on that textFrame's contents. For example, if the textFrame contains the string “ABC”, I want to assign “123” to the Script Label.

      This is what I have so far:

      var myDocItems = app.activeDocument.textFrames;

      if(myDocItems[0].contents == “ABC”)

      myDocItems[0].label = “123”;

      Thanks,

      Rob

    • #63677

      I guess we need a bit more to go on, your code runs fine as is. If you need other labels for other contents, just keep repeating the last two lines.

    • #63682
      rjcjr
      Member

      A couple more things, I'm using CS5 and it seems to be only apply to the first instance it encounters.

      Thanks,

      Rob

    • #63683

      Well yeah, your script checks only the very first text frame. If you want to check *all* frames, you will have to use a loop:

      var myDocItems = app.activeDocument.textFrames;

      for (i=0; i<myDocItems.length; i++)

      if(myDocItems[i].contents == “ABC”)

      myDocItems[i].label = “123″;

    • #63688
      rjcjr
      Member

      That did it, thanks so much!

Viewing 4 reply threads
  • You must be logged in to reply to this topic.
Forum Ads