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

How to find text by "Character Style"

Community Beginner ,
Oct 06, 2017 Oct 06, 2017

HI,

I would like to find a bit of text in the document which have a character style and replace that bit of text with something else without removing the character style.

So for example on the screenshots here. The text saying "Pellentesque efficitur orci i" has the character style applied to it "guidebooklisting_name".

Capture.PNGCapture2.PNG

I would like to replace that text with "This is my real text" so the final result would look like this and would not loose the character style.

Capture3.PNG

I hope that make sense : ) Thank you for your help,

TOPICS
Scripting
1.0K
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

Engaged , Oct 06, 2017 Oct 06, 2017

Hi geza,

hope its helps!!

var myDoc = app.activeDocument;

app.findGrepPreferences.findWhat = "Find Text"

app.findGrepPreferences.appliedCharacterStyle ="guidebooklisting_name";

app.changeGrepPreferences.changeTo = "This is my real text";

myDoc.changeGrep();

Thanks,

Prabu G

Screen Shot 2017-10-06 at 4.31.48 PM.png

Screen Shot 2017-10-06 at 4.32.18 PM.png

Translate
Engaged ,
Oct 06, 2017 Oct 06, 2017

Hi geza,

hope its helps!!

var myDoc = app.activeDocument;

app.findGrepPreferences.findWhat = "Find Text"

app.findGrepPreferences.appliedCharacterStyle ="guidebooklisting_name";

app.changeGrepPreferences.changeTo = "This is my real text";

myDoc.changeGrep();

Thanks,

Prabu G

Screen Shot 2017-10-06 at 4.31.48 PM.png

Screen Shot 2017-10-06 at 4.32.18 PM.png

Thanks,
Prabu
Design smarter, faster, and bolder with InDesign scripting.
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 Beginner ,
Oct 07, 2017 Oct 07, 2017

It helps big time : ) Thank you!

I forgot to say I would like to do this regardless of the content what is in that style. But that is just a small change like this

  1. app.findGrepPreferences.findWhat = "" 
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 Beginner ,
Oct 07, 2017 Oct 07, 2017

Sorry to bother with it but I started to implement the code and now it throws errors.

Code is :

    var myDoc = app.activeDocument; 

    app.findGrepPreferences.findWhat = "";

    app.findGrepPreferences.appliedCharacterStyle = "guidebooklisting_name";

    app.changeGrepPreferences.changeTo = "This is my real name"; 

    myDoc.changeGrep();

   

    return;

And it says

"Invalid value for set property appliedCharacterStyle. Expected String or Style or NothingEnum enumerator but received "guidebooklisting_name".

Driving me nuts  ...

When I first tried everything worked just fine ... now it doesn't.

Any idea ?

Capture.PNG

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 Beginner ,
Oct 07, 2017 Oct 07, 2017

Ah the problem was that I have grouped the styles and style must exist in the document in the root. Just that the error message is well ...

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
Enthusiast ,
Oct 07, 2017 Oct 07, 2017

The charStyle is inside a group?

If yes, try to use:

app.activeDocument.characterStyleGroups.itemByName("name of the

group").characterStyles.itemByName("charStyle name");

Instead of "guidebooklisting_name";

If it's not inside group, just use:

app.activeDocument.characterStyles.itemByName("charStyle name");

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 Beginner ,
Oct 07, 2017 Oct 07, 2017
LATEST

Just relized that as well and we posted more less the same time. Thank you anyway  : )

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