Skip to main content
Known Participant
September 8, 2023
Answered

Can you redefine paragraph styles from a script?

  • September 8, 2023
  • 3 replies
  • 1765 views

Hello, 

I am trying to make a script which can redefine styles from a script  - i know it doesnt make a lot of sence as there is a shortcut for this and also menu for this 

but long story short the menu is small and hiddent and the shortcut by default is also hidden to get to find out what is it 

so a script to hit hit would be faster

advice on this would be much helpful

many thanks

best

Smyth

This topic has been closed for replies.
Correct answer Peter Kahrel

Rob showed you the shortcut key, which is the most convenient. If you must have a script-equivalent for that, try

app.selection[0].appliedParagraphStyle.properties = app.selection[0].properties;

P.

3 replies

Peter Kahrel
Community Expert
Community Expert
September 8, 2023

You can now select a chunk of text with many paragraph styles and it will update all of them

 

No, you're wrong. This statement:

paraStyle.properties = para.properties

says 'the paragraph style's properties are the paragraph's properties'. But the paragraph's properties are just the properties that apply to the whole paragraph, which means that the local overrides (which you were after) are ignored.

 

Maybe you could try something diabolical with textStyleRanges. But you're probably better off explaining your users how to use the keyboard and the KB editor.

Known Participant
September 8, 2023

Umm, when i run it, it has been redefining the paragraph styles panel so i not longer see for example style+

for example two styles one frame header and subheader

I alter both the header and the subheader and i get the + 

 

I select both at the same time and the run the autoRedefine script 



which results in positive feedback



And now I can check the styles 

 

 

The + is gone so the paragraph styles have been updated, additionlly character styles are also taken into account

NB does not have a funtion to undo in one go yet - to be added in 

Not sure if this helps

Best 

Smyth

 

 

 

 

Known Participant
September 8, 2023

O0OOOOOOOOOOOOOOOOOOOOOOOH no, i see the issue - grrrrrrrrrrrrrrrrrrr!!!!

 

Many thanks 

Okay back to work  😞

Peter Kahrel
Community Expert
Peter KahrelCommunity ExpertCorrect answer
Community Expert
September 8, 2023

Rob showed you the shortcut key, which is the most convenient. If you must have a script-equivalent for that, try

app.selection[0].appliedParagraphStyle.properties = app.selection[0].properties;

P.

Known Participant
September 8, 2023

Hi Peter and Rob

Yes thank for showing me the shortcut key, I was looking for a script as mentioned above as the shortcut key is four buttons plus a difficult thing to find in shortcut menues for those who dont go there too often.

Anyhow will look into the script above.

Many thanks as always, 

Smyth

rob day
Community Expert
Community Expert
September 8, 2023

the shortcut key is four buttons

 

You can change it via Edit>Keyboard Shortcuts:

 

Community Expert
September 8, 2023

By redefine do you mean to change the properties of an existing style, if so then we can do so using the script. Just get the object of the desired style and then set the property you want to change

 

var ps = app.documents[0].paragraphStyles.itemByName("My Style")
ps.autoLeading = 10

 

In the script above I have set the autoLeading of a paragraphstyle named "My Style" to 10. For a list of properties of paragraphstyle check the following link

https://www.indesignjs.de/extendscriptAPI/indesign-latest/#ParagraphStyle.html

-Manan

-Manan
Known Participant
September 8, 2023

Hello 

thank you 

I dont undestand as I am not a big scripter 

I have a style lets say style x 

and i have some overrides 


lets say i made it red from black 

the style x now has a + in the paragaph style list

and i want to redefine the style by selecting it and then running the script 

i couldnt quite understand the autoleading script 

and when i checked out the link i didnt see anything for redefining 

best 

smyth

rob day
Community Expert
Community Expert
September 8, 2023

Hi @SmythWharf , There’s a key command for Redefine Style, put your cursor in the text that has the updated definition and Command + Option + Shift + R: