• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

InDesign JS paragraph styles query

Contributor ,
Nov 24, 2021 Nov 24, 2021

Copy link to clipboard

Copied

Hi there,

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.

 

Thanks 🙂

TOPICS
Scripting

Views

261

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Nov 24, 2021 Nov 24, 2021

Copy link to clipboard

Copied

You could try the following with the textframe selected

app.selection[0].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.

-Manan

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Contributor ,
Nov 24, 2021 Nov 24, 2021

Copy link to clipboard

Copied

Hi Manan,

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 🙂

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Nov 24, 2021 Nov 24, 2021

Copy link to clipboard

Copied

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.

-Manan

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Contributor ,
Nov 24, 2021 Nov 24, 2021

Copy link to clipboard

Copied

Great!

Thanks for the help Manan 🙂

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Nov 24, 2021 Nov 24, 2021

Copy link to clipboard

Copied

Hi deckarduk,

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[0].appliedParagraphStyle = app.documents[0].allParagraphStyles[1];

 

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[0].parentStory.texts[0].appliedParagraphStyle =
app.documents[0].allParagraphStyles[1];

 

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.

 

Regards,
Uwe Laubender

( ACP )

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Contributor ,
Nov 24, 2021 Nov 24, 2021

Copy link to clipboard

Copied

Hi Uwe,

 

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 🙂

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Nov 24, 2021 Nov 24, 2021

Copy link to clipboard

Copied

LATEST

"One other thing is that there won't be copy within the textframe."

That's no issue at all. Just test the code.

 

Regards,
Uwe Laubender

( ACP )

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines