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 Answer
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.
-
There is syntax highlighting here too :) (See What is syntax highlighting and how does it work? for more info)– CaiJan 17, 2017 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-VJan 17, 2017 at 18:01
-
1Indent 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.– CaiJan 17, 2017 at 18:07
-
-
It's here: forums.adobe.com/community/illustrator/illustrator_scripting– Silly-VJan 18, 2017 at 15:38