Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
0

Trouble applying paragraph and character styles to text in Illustrator with a script

Community Beginner ,
Jan 20, 2017 Jan 20, 2017

0down votefavorite

I am trying to figure out how to apply paragraph and character styles to text in Illustrator with a script. I have pieced together this and it works sort-of. But I run into the problem that if searchWord1 = "CAUTION:"; with the colon it doesn't work. The same goes for searchWord1 = "¡CUIDADO!:"; I'm assuming it is because of the punctuation? How do I fix this?

var doc = app.activeDocument; var myFrame = doc.textFrames.getByName("back-info"); var myStyle = doc.paragraphStyles.getByName("bullets"); myStyle.applyTo(myFrame.textRange);

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

searchWord1 = "CAUTION";

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) { var boldstyle = doc.characterStyles["bold"]; boldstyle.applyTo(word);
} } } }

TOPICS
Scripting
1.4K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Valorous Hero , Jan 20, 2017 Jan 20, 2017

Here, from the link I posted in previous thread, an altered version of pixxxel's script:

#target illustrator

function test(){

// regex_changeContentsOfWordOrString_RemainFormatting.jsx 

// regards pixxxel schubser 

var doc = app.activeDocument;

var s = new RegExp("CAUTION:", "gi"); 

var myStyle = doc.characterStyles.getByName("MyStyle");

var atf = activeDocument.textFrames[0]; 

 

while (result = s.exec(atf.contents)) { 

    try { 

        aCon = atf.characters[result.index]; 

        aCon.length = re

...
Translate
Adobe
Valorous Hero ,
Jan 20, 2017 Jan 20, 2017

Here, from the link I posted in previous thread, an altered version of pixxxel's script:

#target illustrator

function test(){

// regex_changeContentsOfWordOrString_RemainFormatting.jsx 

// regards pixxxel schubser 

var doc = app.activeDocument;

var s = new RegExp("CAUTION:", "gi"); 

var myStyle = doc.characterStyles.getByName("MyStyle");

var atf = activeDocument.textFrames[0]; 

 

while (result = s.exec(atf.contents)) { 

    try { 

        aCon = atf.characters[result.index]; 

        aCon.length = result[0].length; 

        myStyle.applyTo(aCon);

        } catch (e) {}; 

    } 

};

test();

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jan 20, 2017 Jan 20, 2017

Well done Silly-V​

Nothing to add …

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
Oct 10, 2023 Oct 10, 2023
LATEST

anybody can share video tut on this, nothing happen while using, how to use?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines