Highlighted

Get all text by Character Styles name

New Here ,
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

336

Likes

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

Get all text by Character Styles name

New Here ,
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

337

Likes

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

Likes

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
Reply
Loading...
Feb 11, 2018 0
Community Beginner ,
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

Likes

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
Reply
Loading...
Nov 09, 2020 0
Mentor ,
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

Likes

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
Reply
Loading...
Feb 11, 2018 0
Adobe Community Professional ,
Nov 09, 2020

Copy link to clipboard

Copied

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 )

Likes

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
Reply
Loading...
Nov 09, 2020 0