Macro for setting paragraph space after/before

Get help using and writing Nisus Writer Pro macros.
Post Reply
betalogue
Posts: 7
Joined: 2013-11-12 11:48:25
Location: Canada
Contact:

Macro for setting paragraph space after/before

Post by betalogue »

Hi,

New to Nisus Writer (giving up on Pages and cannot stand MS Word) and trying to create the work environment that I need, with keyboard shortcuts and macros if necessary. (I also use Keyboard Maestro.) I have been able to do a number of things, but there is a particular one that might pose more of a challenge. I often need to adjust space after and space before for paragraphs and I need macros with keyboard shortcuts for the following

set space after to 12 pt
set space after to 0 pt
set space before to 12 pt
set space before to 0 pt
add 6 pt to space after
subtract 6 pt from space after
add 6 pt to space before
subtract 6 pt from space before


I have done this in the past in both MS Word (with VBA) and in Pages (with AppleScript), but obviously it looks like I am going to have to learn a new scripting language in Nisus Writer. I don't mind learning, but the macros above are a more immediate need.

I cannot use paragraph styles for this, because these are manual adjustments that I need to make on a regular basis to paragraphs that are in various existing styles.

The "Spacing" palette in Nisus Writer is not ideal, since it requires manual number input or the use of arrows with 1-pt increments only.

I have found references to ".paragraphSpacingBefore" and ".paragraphSpacingAfter" in the Nisus Macro Reference, but what worries me is that they labelled "read-only", which would suggest that they cannot be set via a macro.

I basically need to know whether this is true or not. If I can set these properties via a macro, I'd appreciate some quick pointers about how to do it. I just need macros that would set the value of the Before and After spacing for the current selection in the ways listed above.

Thanks in advance.
Last edited by betalogue on 2013-11-13 05:08:36, edited 1 time in total.
User avatar
phspaelti
Posts: 1313
Joined: 2007-02-07 00:58:12
Location: Japan

Re: Macro for setting paragraph space after/before

Post by phspaelti »

Boy, you've put your finger on one of Nisus' macro language sore spots :(
Unfortunately, as you note, there are no convenient commands for controlling attributes; Attributes objects are (apparently) immutable, and controlling formatting all has to be done via menu commands.

Given that the best way to create a "set paragraph spacing after to 12-points" macro would look like this:

Code: Select all

$sel = TextSelection.active

$incSpaceAfter = Menu.menuAtPath ‘Increase Space After Paragraph’

$spaceAfterValue = 12

while $sel.text.displayAttributesAtIndex($sel.location).paragraphSpacingAfter < $spaceAfterValue
$incSpaceAfter.activate
end
Note that my use of a menu object to change the spacing isn't really necessary. That is just done to show off :P
philip
User avatar
martin
Official Nisus Person
Posts: 5227
Joined: 2002-07-11 17:14:10
Location: San Diego, CA
Contact:

Re: Macro for setting paragraph space after/before

Post by martin »

Philip is correct: currently the Attributes object only allows one to inspect the formatting inside a document; it cannot be used to change formatting. And also as he says, the way in which to change formatting is normally via menu commands, ie: invoke the same menus the user might normally activate with the mouse. You can do this in a variety of ways. The following are all equivalent:

Code: Select all

# Using the full menu path
:Format:Paragraph Spacing:Increase Space After Paragraph

# Using just the menu name (assuming it is unique)
Increase Space After Paragraph

# Explicitly call out that a menu should be invoked
Menu 'Increase Space After Paragraph'

# Via a Menu object
$menu = Menu.menuAtPath 'Increase Space After Paragraph'
$menu.activate
In all of the above cases one could use the full menu path, instead of just the menu name.

Most of the time this works fairly well (eg: with fonts, colors, etc), but paragraph spacing is unfortunately something of a sticky wicket, as you've seen. I'll file an enhancement that NWP should provide macro commands for explicitly setting the spacing.
betalogue
Posts: 7
Joined: 2013-11-12 11:48:25
Location: Canada
Contact:

Re: Macro for setting paragraph space after/before

Post by betalogue »

Thanks for your replies. I quickly figured out that I could create macros to increase/decrease space before/after by 6-pt increments by just repeating the same command three times:

Code: Select all

Format:Paragraph Spacing:Increase Space After Paragraph
Format:Paragraph Spacing:Increase Space After Paragraph
Format:Paragraph Spacing:Increase Space After Paragraph
It's not very elegant and it's also not ideal performance-wise, since triggering the macro quickly several times in a row (to increase/decrease space before/after) can trigger an alert if the triggers are too close together, because Nisus Writer says that the "macro is already running". But I guess it'll have to do for now.

And thanks Philip for the macro suggestion to set space to a fixed value. Again, it's not particularly elegant, but it works.

For elegance, I guess we'll have to wait until the day that ".paragraphSpacingBefore" and ".paragraphSpacingAfter" are no longer just read-only. I hope this day will come soon. I use paragraph spacing on a regular basis, because I hate multiple returns and I want documents that are well-formed. Thanks Martin for making this an enhancement request. I hate to barge in and start submitting enhancement requests right away, but it looks like Nisus Writer is my main hope these days!
User avatar
martin
Official Nisus Person
Posts: 5227
Joined: 2002-07-11 17:14:10
Location: San Diego, CA
Contact:

Re: Macro for setting paragraph space after/before

Post by martin »

The just released Nisus Writer Pro 2.0.7 includes macro commands that supply this deficiency in controlling paragraph spacing. The newly added commands are:

Code: Select all

Set Paragraph Spacing Before
Set Paragraph Spacing After
We also added a variety of commands for controlling other paragraph attributes:

Code: Select all

Set First Line Head Indent
Set Head Indent
Set Tail Indent
Set Fixed Line Height
Set Line Height Multiple
Set Paragraph Shading Attributes
Set Paragraph Line Attributes For Edges
Please see the macro reference we included in Pro 2.0.7 (available via the Help menu) for more on these commands.
User avatar
phspaelti
Posts: 1313
Joined: 2007-02-07 00:58:12
Location: Japan

Re: Macro for setting paragraph space after/before

Post by phspaelti »

martin wrote:The just released Nisus Writer Pro 2.0.7 includes macro commands that supply this deficiency in controlling paragraph spacing. The newly added commands are:
Great!
philip
betalogue
Posts: 7
Joined: 2013-11-12 11:48:25
Location: Canada
Contact:

Re: Macro for setting paragraph space after/before

Post by betalogue »

martin wrote:The just released Nisus Writer Pro 2.0.7 includes macro commands that supply this deficiency in controlling paragraph spacing. The newly added commands are:

Code: Select all

Set Paragraph Spacing Before
Set Paragraph Spacing After
We also added a variety of commands for controlling other paragraph attributes:

Code: Select all

Set First Line Head Indent
Set Head Indent
Set Tail Indent
Set Fixed Line Height
Set Line Height Multiple
Set Paragraph Shading Attributes
Set Paragraph Line Attributes For Edges
Please see the macro reference we included in Pro 2.0.7 (available via the Help menu) for more on these commands.
Very good indeed. Thanks so much!
Post Reply