1

I have a complicated svg image with hundreds of text labels (a phylogenetic tree). Of those labels, there are certain text boxes that are important to me. I'd like to highlight those labels for interpretation of the figure. I do not know where the important text boxes are in the figure. Is there a way to paste a list of labels into the 'find command' (i.e. lines of text containing the text in the text boxes) and 1) have Illustrator (or something else?) find the text boxes and once found 2) change the font color or highlight coloer?

Thanks for your help.

0

1 Answer 1

1

The Find/Change functionality seems pretty limited in Illustrator, since it can only find and change the text itself. It's much more sophisticated in InDesign where you, among other things, can change the styling of the found text.

I have written a small script which I hope will help you (even though I don't really know much about your document). It does the following:

  • Prompts for a list of words.
  • Finds all text frames in the document.
  • Compares each text frame with each search word.
  • Selects the text frame if there is a match.

The list of words must be a comma-separated list. Spaces are allowed and will be included in the search. So a search for one,two,three will search for "one", "two" and "three", whereas a search for one, two, three will search for "one", " two" and " three", with the spaces included in the search. You can search for whole sentences with spaces, but they can't have commas.

Note that there must be an exact match for the text frame to be selected.

If you need to search for commas, you can change the comma in var words = wordString.split(","); to another character to use as list separator.

Copy/paste the script below to a text editor and save as a .jsx file. Make sure everything in the document is unlocked and run it with File > Scripts > Other Script...


    #target illustrator

    var wordString = prompt(
      "Select text frames containing certain words or phrases." +
      "Input words or phrases to search for as a comma-separated list." +
      "Spaces are allowed and will be included in the search.", 
      "please,insert your,search,phrases like,this"
    );

    if (wordString != undefined) {

      var words = wordString.split(",");
      var document = app.activeDocument;
      var textFrames = document.textFrames;
      var textFrameCount = 0;
      document.selection = null;

      for (var i = 0; i < textFrames.length; i++) {
        var textFrame = textFrames[i];
        var contents = textFrame.contents;
        for (var j = 0; j < words.length; j++) {
          var word = words[j];
          if (word === contents) {
            textFrame.selected = true;
            textFrameCount++;
          }
        }
      }

      alert(textFrameCount + " Text Frame" + (textFrameCount === 1 ? "" : "s") + " selected");

    }

I'm unsure of how robust the script is - please let me know if it works for you.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.