Hi Devsel,
IMHO there would be easier ways to get started with InDesign scripting than working with nested styles and overrides—you should first study how regular styles work.
Anyway,
Basically we have to deal with both paragraph attributes and character attributes. What you seem to focus on is character attributes overrides. But as paragraph styles also contain character attributes, a full report of what happens to some portion of text has to include, I'm afraid, the paragraph style level. Here is a recap of those cascading effects which affect character attributes:
1. Paragraph style level (incl. inheritance mechanism, cf basedOn property).
2. Manually edited paragraph attributes (i.e. "paragraph overrides," which may include nested style overrides!)
3. Nested styles (i.e. stack of automated character styles dictated by the current paragraph attributes.)
4. Manually applied—not [None]—character style (incl. inheritance mechanism, cf basedOn property.)
5. Manually edited character attributes (which override the current character style.)
Given a piece of Text, its textStyleRanges collection allows to identify discontiguities at levels 4 and 5, that is, manually applied changes regarding either character style or attributes. (Note however that a character style might be 'empty' relative to its inherited attributes, meaning that no actual change is done in terms of visible properties, although this still is reported as a range break.)
Now, about nested styles (level 3), see them as a stack of pointers that involve existing character styles in an automated way (from the paragraph level.) Technically nested styles are distributed in three collections: NestedStyles, NestedLineStyles, and NestedGrepStyles. Given a paragraph (or a paragraph style) P, you need to inspect both P.nestedStyles, P.nestedLineStyles, and P.nestedGrepStyles to have a complete view of all nested styles defined in P, which does not mean that the underlying character styles are all actually applied.
[Note: As nested styles are managed as paragraph attributes, you can see them in fact from any text portion inside a paragraph, but do not inspect them from a larger portion, e.g. a Story, because you will then lose specific data.]
Since changes resulting from nested styles DO NOT APPEAR as text style ranges, they do not count as overrides, so the crucial question is to identify pieces of text that undergo the effects of some nested style(s). Here we have a useful property, myText.appliedNestedStyles, which returns an array of all character styles that actually act on myText as a result of nested/nestedLine/nestedGrep-style mechanism. But this property is reliable only if myText is a 'uniform' range regarding the nested styles applied. If you select a larger portion, results won't be relevant.
To determine nested styled texts that also undergo manual overrides (level 5), you need to extract from the overridden text style ranges the uniform parts which have a non-empty appliedNestedStyles array. Problem is, overridden ranges are not easy to identify because the styleOverridden property does not make any distinction between paragraph-level and character-level overrides! That's the deepest issue.
So, unfortunately, I have no simple solution so far. We can get the style ranges and select those meeting the condition styleOverridden==true, but I don't know how to easily exclude the 'good boys' from there... (A deep attribute compare routine could be required for a perfect solution
)
The draft code I suggest is just an approximation, assuming that paragraph styles are properly applied and do not provide misleading overrides:
// THIS CODE IS JUST A FIRST DRAFT
// ===============================
var story = app.selection[0].parentStory; // assuming some text is selected
var ranges = story.textStyleRanges,
nr = ranges.length, r,
t, a, i, iMin, iMax, cur, s,
res = [];
// Loop in the style ranges
// ---
for( r=0 ; r < nr ; ++r )
{
t = ranges
; if( !t.styleOverridden || !t.appliedNestedStyles.length ) continue;
t = t.characters;
if( !t.length ) continue;
// Inspect this range (regarding nested styles.)
// ---
a = t.everyItem().appliedNestedStyles;
iMax = a.length-1;
cur = a[iMin=0].join('|');
for( i=1 ; i <= iMax ; ++i )
{
s = a.join('|');
if( s == cur ) continue;
cur && res.push(t.itemByRange(iMin,i-1).getElements()[0]);
iMin = i;
cur = s;
}
cur && res.push(t.itemByRange(iMin,iMax).getElements()[0]);
}
// Show the results as contents.
// ---
i = res.length;
while( i-- ){ res=res.contents }
alert(
"The nested-styled text overrides should be in this array:\r\r\r" +
res.join('\r--------------\r')
);
Hope that can help.
@+
Marc
Sign up
Already have an account? Login
To post, reply, or follow discussions, please sign in with your Adobe ID.
Sign inSign in to Adobe Community
To post, reply, or follow discussions, please sign in with your Adobe ID.
Sign inEnter your E-mail address. We'll send you an e-mail with instructions to reset your password.


