Skip to main content
kylamrtn21
Participating Frequently
January 18, 2017
Question

script for applying paragraph and character styles in illustrator

0down votefavorite

I've been trying to manipulate the sample scripts from ADOBE ILLUSTRATOR CC SCRIPTING REFERENCE: JAVASCRIPT without any success (I am brand new to JavaScript). I would like to be able to find specific text in an Illustrator document and apply paragraph and character styles with a script. I would like to be able to automate this feature with a batch for multiple documents.

I can figure out how to apply a style to the whole text box but I would like to be able to search for key words and sentences to apply the styles to.

Help Please! Thanks!

8 replies

Loic.Aigon
Legend
January 18, 2017

Just in the doc page 240. I just tweaked the sample here:

var main = function() {

  var doc;

  if ( app.documents.length > 0 && app.activeDocument.textFrames.length > 0 ) {

  // Create the color to apply to the words

  wordColor = new RGBColor();

  wordColor.red = 255;

  wordColor.green = 0;

  wordColor.blue = 255;

  // Set the value of the word to look for

  searchWord1 = "myContent";

  // Iterate through all words in the document

  // and color the words that match searchWord

  for ( i = 0; i < app.activeDocument.textFrames.length; i++ ) {

  textArt = activeDocument.textFrames;

  for ( j = 0; j < textArt.words.length; j++) {

  word = textArt.words;

  if ( word.contents == searchWord1 ) {

  //:word.filled = true;

  //word.fillColor = wordColor;

  app.activeDocument.characterStyles.getByName ( "myCharacterStyle" ).applyTo ( word );

  }

  }

  }

  }

}

var u;

main();

Translate
kylamrtn21
Participating Frequently
January 18, 2017

This works when I use "CAUTION" but not "CAUTION:". What do I have to change in order to use punctuation in my string? Or to use a full sentence as the search string?

Translate
Silly-V
Legend
January 18, 2017

Here is some more information:

https://forums.adobe.com/message/8925523#8925523

Any of the snippets there shall help you, I think.

Translate