Reply to topic  [ 7 posts ] 
Macro for setting paragraph space after/before 
Author Message

Joined: 2013-11-12 11:48:25
Posts: 5
Location: Canada
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.

_________________
Pierre Igot
http://www.betalogue.com
@betalogue


Last edited by betalogue on 2013-11-13 05:08:36, edited 1 time in total.



2013-11-12 13:19:42
Profile WWW
User avatar

Joined: 2007-02-07 00:58:12
Posts: 876
Location: Japan
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:
$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


2013-11-12 17:17:34
Profile
Official Nisus Person
User avatar

Joined: 2002-07-11 17:14:10
Posts: 4251
Location: San Diego, CA
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:
# 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.


2013-11-12 22:00:37
Profile WWW

Joined: 2013-11-12 11:48:25
Posts: 5
Location: Canada
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:
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!

_________________
Pierre Igot
http://www.betalogue.com
@betalogue


2013-11-13 05:05:03
Profile WWW
Official Nisus Person
User avatar

Joined: 2002-07-11 17:14:10
Posts: 4251
Location: San Diego, CA
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:
Set Paragraph Spacing Before
Set Paragraph Spacing After

We also added a variety of commands for controlling other paragraph attributes:
Code:
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.


2013-11-26 23:31:01
Profile WWW
User avatar

Joined: 2007-02-07 00:58:12
Posts: 876
Location: Japan
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


2013-11-26 23:43:23
Profile

Joined: 2013-11-12 11:48:25
Posts: 5
Location: Canada
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:
Set Paragraph Spacing Before
Set Paragraph Spacing After

We also added a variety of commands for controlling other paragraph attributes:
Code:
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!

_________________
Pierre Igot
http://www.betalogue.com
@betalogue


2013-11-28 11:41:29
Profile WWW
Display posts from previous:  Sort by  
Reply to topic   [ 7 posts ] 

Who is online

Users browsing this forum: No registered users and 3 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB® Forum Software © phpBB Group
Designed by ST Software