Copy link to clipboard
Copied
Hey,
In the Adobe InDesign CS5.5 Scripting Guide, there's a paragraph that reads:
Why use the applyParagraphStyle method instead of setting the appliedParagraphStyle property of
the text object? The applyParagraphStyle method gives the ability to override existing formatting;
setting the property to a style retains local formatting.
However, when I use applyParagraphStyle like this: text_frame.parentStory.paragraphs[0].applyParagraphStyle(title_style, true); the color and font family of the paragraph is not changed (even though the size is).
Am I missing something? Here's the full code I'm using:
var products = load_products();
var doc = app.documents.add();
var title_style = doc.paragraphStyles.item('Product - Title');
for ( var i = 0, l = products.length; i < l; i++ ) {
var text_frame = doc.pages[0].textFrames.add();
text_frame.geometricBounds = [
(100 * i) + 'pt',
'6pt',
(100 * i + 240) + 'pt',
'240pt'
];
text_frame.contents = products.title;
text_frame.parentStory.paragraphs[0].applyParagraphStyle(title_style, true);
text_frame.fit(FitOptions.frameToContent);
var b = text_frame.geometricBounds;
}
Edit: if after ruinning the script I go to apply the style to this paragraph, I get an option in the context menu to clear overrides; and if I do so, then the color and font-family are changed.
Message was edited by: Zoffix222
Character Styles should not be cleared by clear overrides.
If you set appliedCharacterStyle = doc.characterStyles[0] to change character style to [None] before overriding, character style formatting will be cleared.
Copy link to clipboard
Copied
That only works on paragraph level overrides.
To clear character level overrides, you need to use text_frame.parentStory.paragraphs[0].clearOverrides() as well.
Harbs
Copy link to clipboard
Copied
I tried that, but there is no effect.
Using story editor, I can see the paragraph style applied, but the character styles are not cleared...
Copy link to clipboard
Copied
Before or after appliying the para style?
Copy link to clipboard
Copied
I'm using clearOverrides before applying the style:
text_frame.parentStory.paragraphs[0].clearOverrides(OverrideType.ALL);
text_frame.parentStory.paragraphs[0].applyParagraphStyle(title_style, true);
If I comment out the .applyParagraphStyle, the only thing different is text is no longer center-justified, but all else looks the same.
Could the problem be that my styles are not created via the script, but are actually default styles I setup in InDesign?
Copy link to clipboard
Copied
Character Styles should not be cleared by clear overrides.
If you set appliedCharacterStyle = doc.characterStyles[0] to change character style to [None] before overriding, character style formatting will be cleared.
Copy link to clipboard
Copied
Hey, Awesome! That worked.
But why? The docs for clearOverrides list OverrideType.CHARACTER_ONLY.... oh never mind.
The overrides clears only the overrides but not the styles
That makes sense. Thanks!
Copy link to clipboard
Copied
Right. Character styles are not overrides at all!
Overrides by definition is styling not applied using styles.
Copy link to clipboard
Copied
I am trying to get a script to clear all overrides in selected paragraph and/or text box.
Reason for this is I want a shortcut key to fix this e.g. F1.
Have tried with the code mentioned abowe but cant seem to get it to work (I am an Indesign Power user but a bit new to coding).
The best I have found is:
app.documents[0].stories.everyItem().clearOverrides()
But that clears ALL overrides in the whole document – and thats not what I want.
Can this be done?
Copy link to clipboard
Copied
Well, if that's what you need, then how about:
app.selection[0].clearOverrides()
which will clear the overrides in the current selection
Ariel
Copy link to clipboard
Copied
I cant get this to work. My text is placed by an automated command to Indesign. But everytime I must select the text and "force" Indesign to use "PARAGRAPH STYLE NAME", then the next format, clear text format. I do this from the drop-down menu in paragraph style palette.
Any way this can be scriptable to work whatever the paragraph style is?
This would be a real lifesaver for me.
Copy link to clipboard
Copied
This was exactly what I needed
app.documents[0].stories.everyItem().clearOverrides()