Welcome Dialog

Welcome to the Community!

We have a brand new look! Take a tour with us and explore the latest updates on Adobe Support Community.


Creating a new paragraph style with justification properties.

Participant ,
Nov 09, 2021 Nov 09, 2021

Copy link to clipboard

Copied

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

Views

45

Likes

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

correct answers 1 Correct answer

Enthusiast , 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

Likes

Translate

Translate
Enthusiast ,
Nov 09, 2021 Nov 09, 2021

Copy link to clipboard

Copied

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

Likes

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

Copy link to clipboard

Copied

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

Likes

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

Copy link to clipboard

Copied

LATEST

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

- Mark

Likes

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