Select by Style macro

Get help using and writing Nisus Writer Pro macros.
Post Reply
User avatar
phspaelti
Posts: 914
Joined: 2007-02-07 00:58:12
Location: Japan

Select by Style macro

Post by phspaelti » 2013-11-13 08:06:03

The following macro is a little demonstration of the increasing power of Nisus' macro language. A long time ago Kino wrote a series of macros to do "Select by" for various properties including styles. (I believe these may be supplied among the standard set in the "Find" folder.)

They are certainly nice macros, but they are not for the faint of heart. Here is an attempt to rewrite the "Select by Style" macro using some of the new features in NWP. The most important is the ability to do Find using a Style object as the find expression. This makes the macro a lot shorter :wink:
Select By Style (new).nwm
(18.1 KiB) Downloaded 223 times
And this brings me to a feature request: it would be nice if the same could be done with Attributes objects. And how about being able to use style or attributes as replace arguments as well (in which case they would apply the style/attributes to the found selections)?
philip

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

Re: Select by Style macro

Post by martin » 2013-11-13 23:12:22

They are certainly nice macros, but they are not for the faint of heart.
That's certainly true! Kino is very clever and accomplished great things using macros, but had to manage quite a bit of complexity to achieve his goals.
Here is an attempt to rewrite the "Select by Style" macro using some of the new features in NWP. The most important is the ability to do Find using a Style object as the find expression. This makes the macro a lot shorter :wink:
Ah, wonderful– much cleaner! I especially enjoy seeing the use of the "getProperty" command to dynamically loop through the different style types.
And this brings me to a feature request: it would be nice if the same could be done with Attributes objects. And how about being able to use style or attributes as replace arguments as well (in which case they would apply the style/attributes to the found selections)?
It sounds like a good idea to me, I'll file the suggestion. Thank you Philip.

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

Re: Select by Style macro

Post by phspaelti » 2013-11-14 00:36:24

martin wrote:I especially enjoy seeing the use of the "getProperty" command to dynamically loop through the different style types.
Yes, it was great to find a use for that :)
There are a couple of other interesting commands in Nisus' macro language. My favorite is .arrayByMakingValuesDoCommand which I now try to use at every opportunity. :P For example here is a truly barebones version of the select by style macro (which dispenses with the fancy interface altogether):

Code: Select all

$doc = Document.active
$styleNames = $doc.allStyles.arrayByMakingValuesDoCommand 'name'
$styleName = prompt Options 'Choose a style', '', 'Find', $styleNames
$style = $doc.styleWithName($styleName)
Find All $style
philip

Post Reply