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

Get all text by Character Styles name

New Here ,
Feb 11, 2018 Feb 11, 2018

Copy link to clipboard

Copied

How can i get all text that have the same Character Styles by the Character Styles name with indesign script?

TOPICS
Scripting

Views

1.3K

Translate

Translate

Report

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 ,
Feb 11, 2018 Feb 11, 2018

Copy link to clipboard

Copied

I've always used Adobe findText (or findGrep). Like this:

var charStyleName = "YourStyleName";

app.findTextPreferences = NothingEnum.NOTHING;

app.findTextPreferences.appliedCharacterStyle = app.activeDocument.characterStyles.item(charStyleName);

var foundText = app.activeDocument.findText();

As Capt. Obvious might say: charStyleName must be a valid style name for the active document. foundText will be an array of text objects using that character style.

If there's a way to test all of the text objects in the document, I'd like to know what it is.

Bob

Votes

Translate

Translate

Report

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 ,
Nov 09, 2020 Nov 09, 2020

Copy link to clipboard

Copied

Hi!

 

I'm trying to cycle through multiple character style folders/groups. They all have the same character styles inside them, for alternative layouts, here I need to do a findText for "asdf":

styleGroupList=["style1","style2","style3"]
styleGroupListLength = styleGroupList.length;

for (i = 0; i < styleGroupListLength; i++) {
  // csg = Character Style Group
  csg = app.activeDocument.characterStyleGroups.itemByName(styleGroupList[i]);
  app.findTextPreferences.appliedCharacterStyle = csg.characterStyles.itemByName("asdf");
}

But the last line keeps returning an "Object is invalid"-error. I think it has trouble with the combination of findTextPreferences and character style groups.

 

Somewhere else in the script, csg works:

var asdf = csg.characterStyles.itemByName("asdf");

 

And findTextPreferences does work without csg in the script above:

app.findTextPreferences.appliedCharacterStyle = app.activeDocument.characterStyles.itemByName("asdf");

 

So it seems to have to do with the combination.

Any clues...?

 

Thanks & all the best,

Mathisse

Votes

Translate

Translate

Report

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
Mentor ,
Feb 11, 2018 Feb 11, 2018

Copy link to clipboard

Copied

Hi,

Use app.findTextPreferences.appliedCharacterStyle in a loop.

I mean iterate through all charStyles in a doc and change this preference each step.

Method doc.findText() will return an array with all (continious) texts with current charStyle applied.

Jarek

Votes

Translate

Translate

Report

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 ,
Nov 09, 2020 Nov 09, 2020

Copy link to clipboard

Copied

LATEST

Hi Matthisse,

you could access all character styles with:

app.documents[0].allCharacterStyles

That returns an array of character styles.

Loop that array to get all character styles with that particular name ( "asdf") and store them into a new array.

Then loop that array to do whatever you like to do with the found instances of character style "asdf".

 

Regards,
Uwe Laubender

( ACP )

Votes

Translate

Translate

Report

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