Skip to main content
Inspiring
January 2, 2014
Question

Nested styles and textStyleRanges

  • January 2, 2014
  • 2 replies
  • 2344 views

HI all!

I have to recognize all textStyleRanges in my documents.

Unfortunately character styles described by a nested style are not really applied to the text and the paragraph looks like a single textStyle range.

Is it possible to apply the characterStyles from nested styles?

thanks.

Ivan

This topic has been closed for replies.

2 replies

Community Expert
January 2, 2014

@Ivan – recently I posted something about text style ranges.

Just for illustrating the problems, see my answers #3 to #6 in:

 

Get text selection and properties
poortip87, Dec 18, 2013
https://community.adobe.com/t5/indesign-discussions/get-text-selection-and-properties/td-p/5734157

 

poortip87

Get text selection and properties

http://forums.adobe.com/message/5943951#5943951

 

Uwe

 

PS:

Corrected the link to the discussion.

 

Regards,
Uwe Laubender
( Adobe Community Expert )

Kai Rübsamen
Participating Frequently
January 2, 2014

Hi,

nested character Styles ARE kind of applied to the text, but are hidden in some cases, because they are not at the same level as paragraph styles. Because they are applied to the text, they can be found with find/change.

A possible solution would be to seek the appropriate text and apply the character Style twice. At the end you can remove the doubly assigned cStyle.

var curSel = app.selection[0];

var curStory = curSel.parentStory;

var allRanges = curStory.textStyleRanges;

alert (allRanges.length);

var PARA_STYLE_NAME = 'MyParaStyle';

var CHAR_STYLE_NAME = 'MyCharStyle';

var doc = app.activeDocument;

var pStyle = doc.paragraphStyles.itemByName(PARA_STYLE_NAME);

var cStyle = doc.characterStyles.itemByName(CHAR_STYLE_NAME);

app.findGrepPreferences = app.changeGrepPreferences = null;

app.findGrepPreferences.appliedParagraphStyle = pStyle;

app.findGrepPreferences.appliedCharacterStyle = cStyle;

app.changeGrepPreferences.appliedCharacterStyle = cStyle;

doc.changeGrep();

alert( allRanges.length );

Kai

fivanAuthor
Inspiring
January 2, 2014

Hi Kai.

I do not understand what do you mean with "nested character Styles ARE kind of applied to the text" but your sample seems to be very usefull.

Thanks.

Ivan

Kai Rübsamen
Participating Frequently
January 2, 2014

Hi Ivan,

> I do not understand what do you mean with "nested character Styles ARE kind of applied to the text

If you apply a character style direct to some text, the paragraph style and character style are in the same hierarchy. If you apply a character style as a part of a nested style, the character style is a part of the pStyle and therefore one level deeper in the hierarchy.

My understanding is, that in every case, the character style is applied to the text, even if it is not visible to other programs or in this case for a textStyleRange. Therefore, it is possible to find those nested styles or GREP-Styles too  or export it e.g. to EPUB.