Please can someone help with a quick question regarding InDesign Javacript.
Is it possible to access or apply paragraph styles via the selection object or can it only be done via the document object?
I've tried a few different things but as yet haven't solved it.
I'm trying to apply a paragraph style to the text frame I have selected.
You could try the following with the textframe selected
app.selection.parentStory.appliedParagraphStyle = "Paragraph Style 1"
textframe does not have the appliedParagraphStyle property so you will have to use objects like paragraph, story or text objects to apply the paragraph style.
Thanks for the help 🙂
I'm going to have another try using your code however, I'm pretty sure I've tried this method.
I think I encountered an error because the text frame doesn't have any copy in it.
Thanks once again 🙂
If by copy you mean that your texframe is empty then you should not encounter any error because even if you don't have any content still the frame has a corresponding story object.
Thanks for the help Manan 🙂
do you mean selected paragraph styles in the Paragraph Styles panel?
That's doable, but it's not reliable. We had a discussion about that a year ago, I think.
FWIW: The document comes with a allParagraphStyles array you can loop.
The order of the styles stored in this array is the order you find in your Paragraph Styles panel.
If text is selected you could ask for appliedParagraphStyle for every paragraph of the selection.
To apply a paragraph style to the text of a selected text frame:
// Apply the basic paragraph style to the text of your text frame: app.selection.appliedParagraphStyle = app.documents.allParagraphStyles;
If the text frame is not threaded to another one and the text frame is in overset you can apply the paragraph style also to the overset text using the parent story:
// Apply the basic paragraph style to the story of your text frame: app.selection.parentStory.texts.appliedParagraphStyle = app.documents.allParagraphStyles;
Note: If you have tables and footnote texts in your selected text frame a different code is required to reach the text in the text cells and in the footnote texts.
( ACP )
Thanks for the indepth help, it's much appreciated.
Yes, I do mean styles from the Paragraph Styles panel.
The only thing is the textframe will be the selection, not the contents within.
One other thing is that there won't be copy within the textframe.
I'll have a play around with the code you've supplied.
Many thanks 🙂
"One other thing is that there won't be copy within the textframe."
That's no issue at all. Just test the code.
( ACP )