Link to home
Start Free TrialLog in
Avatar of pindemad2
pindemad2

asked on

changing contents of TextStyleRange

We use javascript to search and replace text by iterating through all textstyleranges in a indesign document.
Usually this works fine, but for some documents we get a problem: once content is changed in a textStyleRange its ParagraphStyle is automatically applied to the next TextStyleRange (eg. maybe changing a normal line to a headline)

This only happens for textStyleranges that are stored weirdly "recursively" (the textStyleRanges collection in a textStyleRange contains the current textStyleRange and the next textStyleRange)
Avatar of steven_bryant
steven_bryant

The definition of textStyleRange is "A continuous range of identical text formatting attributes". This can change in middle of a paragraph. So changing paragraph style of range may affect next range paragraph style if in the same paragraph.
Avatar of pindemad2

ASKER

the only member I change in textStyleRange is contents - InDesign then changes the paragraphStyle of the next textStyleRange
could you post a short sample of code that illustrates your point.
basically its:
...
var page=doc.pages.item(0);
var textframe=page.textFrames.item(0);
var textStyle=textFrame.textStyles.item(0);
var secondTextStyle=textFrame.textStyles.item(1);
textStyle.contents='some text';

at this point secondTextStyle paragraphStyle changes to the same as that of textStyle.

textStyle.textStyles has 2 members: the first is textStyle itself the second is secondTextStyle
I imagine you mean

var doc = app.activeDocument;
var page=doc.pages.item(0);
var textFrame=page.textFrames.item(0);
var textStyle=textFrame.textStyleRanges.item(0);
var secondTextStyle=textFrame.textStyleRanges.item(1);
textStyle.contents='some text\r';

I'm assuming that each range is a complete paragraph including paragraph end character, making it necessary to add \r to text.

My test shows the opposite that the second paragraph gets paragraph style of first paragraph.



sorry, of cource you are right that I meant textStyleRange (not textStyle)

and the problem is exactly that the paragraphStyle of the second textStyleRange changes to that of the first when the contents of the first textStyleRange is changed.

I want to change the contents of the first textStyleRange - with no changes to any paragraphStyles
ASKER CERTIFIED SOLUTION
Avatar of steven_bryant
steven_bryant

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Thank you!
I will give more attention to \r in InDesign scripting in the future :)