0

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. Any help would be appreciated!

1

I suggest for you to check out the Illustrator scripting forum if you would like to learn more about Illustrator scripting. Besides being populated with all people who do scripting for Illustrator, they also have syntax highlighting in the forum.

Anyway, here is an example snippet:

//@target illustrator
function test(){
  var doc = app.activeDocument;
  var myFrame = doc.textFrames.getByName("MyText");
  var myStyle = doc.characterStyles.getByName("MyStyle");
  myStyle.applyTo(myFrame.textRange);
};
test();

Here you can see that it's grabbing a textbox based on its name in the layers panel and it's getting an existing character style the same way. There are other ways to get at those objects when you don't know the name too. The character style object has an 'applyTo' command, but it doesn't just take a text box as the input, it actually takes a 'textRange' object of the text frame items (of which there can be several sub-text-ranges). In this example it's just applying the style to the entire text box, but you can use text matching operations to isolate only certain words or manipulate other textFrame properties such as the paragraphs and lines of text to apply styles to them.

In order to really explain the can of worms that's Illustrator scripting text api it is kind of a lot for someone just starting out, so I hope this is a good start for you.

| improve this answer | |
  • There is syntax highlighting here too :) (See What is syntax highlighting and how does it work? for more info) – Cai Jan 17 '17 at 16:34
  • Wow how did you do that! I'm going to have to read the help more in-depth, but looking at the post you edited, I can't see where any special tags are to say what the highlighting is. – Silly-V Jan 17 '17 at 18:01
  • 1
    Indent 4 spaces for code blocks (which get highlighting). Or you can select the code and hit ctrl+k (or cmd+k on mac). Backticks are for inline code and don't get highlighted. – Cai Jan 17 '17 at 18:07
  • Thank you! Where is this Illustrator scripting forum? – kmrtn Jan 18 '17 at 14:25

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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