Page 1 of 1

Paragraph shading

Posted: 2014-01-19 05:07:57
by js
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.

Re: Paragraph shading

Posted: 2014-01-19 05:47:46
by phspaelti
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.

Re: Paragraph shading

Posted: 2014-01-19 06:28:06
by phspaelti
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

Re: Paragraph shading

Posted: 2014-01-19 15:53:21
by js
Thank you.
I did not understand that "color" as argument of ShadingAttributes can't be a simple color name like "yellow"

Re: Paragraph shading

Posted: 2014-01-19 17:40:02
by phspaelti
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: