Change the Normal Style via Macro

Get help using and writing Nisus Writer Pro macros.
Post Reply
User avatar
loulesko
Posts: 124
Joined: 2008-01-20 11:08:35
Location: California
Contact:

Change the Normal Style via Macro

Post by loulesko »

Hello all,

Wondering if anyone can point me in the right direction to create macro which will change the font of the Normal paragraph style in a document.

Many thanks,

Lou
adryan
Posts: 563
Joined: 2014-02-08 12:57:03
Location: Australia

Re: Change the Normal Style via Macro

Post by adryan »

G'day, Lou et al

Why not just change it in the Style Sheet?

Alternatively, as long as the cursor is situated within a paragraph with Normal Style (because that's the one you want to change), you could invoke a simple Macro with the following two lines (with your choice of font):–

Format:Paragraph Style:Select All in Style
Format:Font:All Fonts:Apple Chancery

Cheers,
Adrian
MacBook Pro (M1 Pro, 2021)
macOS Ventura
Nisus Writer user since 1996
User avatar
phspaelti
Posts: 1313
Joined: 2007-02-07 00:58:12
Location: Japan

Re: Change the Normal Style via Macro

Post by phspaelti »

Hi Lou,
The simplest way to do this is in a macro is to paste a sample that contains the relevant style. The macro language has a special command for this, and so the following code will do this:

Code: Select all

$doc = Document.active
$styleSample = 'Example'
$doc.addStyles $styleSample, 'replace'
Note that for this code to work $styleSample will need to have the relevant style applied, so you will need to paste it into your macro. If your macro already has a different Normal style, you will need to delete it from the macro or rename it.
Alternatively you can collect a sample from some other file and transfer it to the target document using this type of code.
HTH
Philip
philip
User avatar
loulesko
Posts: 124
Joined: 2008-01-20 11:08:35
Location: California
Contact:

Re: Change the Normal Style via Macro

Post by loulesko »

Philip,

Many thanks for the details.

Lou
User avatar
martin
Official Nisus Person
Posts: 5228
Joined: 2002-07-11 17:14:10
Location: San Diego, CA
Contact:

Re: Change the Normal Style via Macro

Post by martin »

loulesko wrote: 2023-06-21 19:53:40 Wondering if anyone can point me in the right direction to create macro which will change the font of the Normal paragraph style in a document.
As usual there's a few different ways you could come at this, depending on your exact situation. But here's what's probably the most general purpose macro solution:

Code: Select all

# select the style to modify
$doc = Document.active
$style = $doc.styleWithName("Normal")
Style.setStyleViewEditingStyles(Array.new($style))
# apply desired formatting
Menu "Format:Font:All Fonts:Arial"
# return to normal document mode
Menu "View:Draft View"
I hope that helps!
User avatar
loulesko
Posts: 124
Joined: 2008-01-20 11:08:35
Location: California
Contact:

Re: Change the Normal Style via Macro

Post by loulesko »

Martin

Many thanks. This is super helpful. Bit of an experiment for workflow from Nisus to Google Docs for a book project.

-Lou
Post Reply