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)
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)
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.
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.
ASKER
basically its:
...
var page=doc.pages.item(0);
var textframe=page.textFrames. item(0);
var textStyle=textFrame.textSt yles.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
...
var page=doc.pages.item(0);
var textframe=page.textFrames.
var textStyle=textFrame.textSt
var secondTextStyle=textFrame.
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.textSt yleRanges. item(0);
var secondTextStyle=textFrame. textStyleR anges.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.
var doc = app.activeDocument;
var page=doc.pages.item(0);
var textFrame=page.textFrames.
var textStyle=textFrame.textSt
var secondTextStyle=textFrame.
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.
ASKER
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
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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thank you!
I will give more attention to \r in InDesign scripting in the future :)
I will give more attention to \r in InDesign scripting in the future :)