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

Creating a new paragraph style with justification properties.

Participant ,
Nov 09, 2021 Nov 09, 2021

I'm having a little trouble understanding how to script the creation of a new paragraph style and define its justification settings at the same time. This example makes sense:

 

app.activeDocument.paragraphStyles.add(name:"New Style", appliedFont:"Arial\tRegular", pointSize:"12pt")

 

but how do I make that paragraph, say, center align? Currently I do it as 2 steps: Create the style as above and them modify the style properties, like:

 

app.activeDocument.paragraphStyles.itemByName("New Style").properties = {justification: Justification.CENTER_ALIGN}

 

Is there a way to do it in one step? 

 

Thanks!

 

TOPICS
Scripting
546
Translate
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

correct answers 1 Correct answer

Community Expert , Nov 09, 2021 Nov 09, 2021

Hi Dan,

The add() method of ParagraphStyles has a single optional argument called 'withProperties" which is expecting an object—something in braces {} with key: value pairs seperated by commas. So:

 

app.activeDocument.paragraphStyles.add({
    name: "New Style",
    appliedFont: "Arial\tRegular",
    pointSize: "12pt",
    justification: Justification.CENTER_ALIGN
})

 

 - Mark

Translate
Community Expert ,
Nov 09, 2021 Nov 09, 2021

Hi Dan,

The add() method of ParagraphStyles has a single optional argument called 'withProperties" which is expecting an object—something in braces {} with key: value pairs seperated by commas. So:

 

app.activeDocument.paragraphStyles.add({
    name: "New Style",
    appliedFont: "Arial\tRegular",
    pointSize: "12pt",
    justification: Justification.CENTER_ALIGN
})

 

 - Mark

Translate
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
Participant ,
Nov 10, 2021 Nov 10, 2021

Thanks, Mark. I dunno what I was missing that didn't work for me yesterday, but it works now!

Translate
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 10, 2021 Nov 10, 2021
LATEST

Maybe accidentally left out the braces {} as per example in your post? Most errors I get writing scripts are simple typos.

- Mark

Translate
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