Paragraph shading

Get help using and writing Nisus Writer Pro macros.
Post Reply
js
Posts: 229
Joined: 2007-04-12 14:59:36

Paragraph shading

Post by js » 2014-01-19 05:07:57

I wonder how Paragraph Shading can be applied via a macro to paragraphs with a selection.
I fear did not understand how to use the commands given in the Macro help file.

User avatar
phspaelti
Posts: 939
Joined: 2007-02-07 00:58:12
Location: Japan

Re: Paragraph shading

Post by phspaelti » 2014-01-19 05:47:46

I thought that I had written a macro to do such a thing, but I can't find it. So maybe I was just imagining things. I was probably thinking about Table cells.

The fact is that attributes are still very much a step-child in Nisus' macro language. They can't be created, and attribute objects retrieved from the text can't be changed, or applied to other selections. There is an ".addNewStyle" command (for document objects) which takes an attribute object as argument, but that's about it.

One would hope that a future update would add some commands like:

Code: Select all

Attributes.new [attribute list]
Selection.apply [attributes object]
but at this point this is just a wish.
philip

User avatar
phspaelti
Posts: 939
Joined: 2007-02-07 00:58:12
Location: Japan

Re: Paragraph shading

Post by phspaelti » 2014-01-19 06:28:06

Ok, so maybe I wasn't imagining things.
If you look in the macro reference in the section "Formatting Text" you will find the following:

Code: Select all

Set Paragraph Shading Attributes shadingAttrs
So there you have it.

Here's a code example:

Code: Select all

$lightGray = Color.newWithHexTriplet 'CCCCCC'
$shade = ShadingAttributes.newWithSolidColor $lightGray
Set Paragraph Shading Attributes $shade
philip

js
Posts: 229
Joined: 2007-04-12 14:59:36

Re: Paragraph shading

Post by js » 2014-01-19 15:53:21

Thank you.
I did not understand that "color" as argument of ShadingAttributes can't be a simple color name like "yellow"

User avatar
phspaelti
Posts: 939
Joined: 2007-02-07 00:58:12
Location: Japan

Re: Paragraph shading

Post by phspaelti » 2014-01-19 17:40:02

js wrote:Thank you.
I did not understand that "color" as argument of ShadingAttributes can't be a simple color name like "yellow"
Indeed. The extra step needed to use color in any command is a bit of a bother. And the shading attributes object command ".newWithBlendColors" requires two colors.
For this reason I usually use ".newWithPatternType" with argument 'Blend', but then you still need to set the blend ratio separately.

Code: Select all

$shade = ShadingAttributes.newWithPatternType 'Blend'
$shade.blendRatio = 0.25
Set Paragraph Shading Attributes $shade
Well, we can achieve what we want, so we're not complaining, we're not complaining… :wink:
philip

Post Reply