Page 1 of 1

Select by Style macro

Posted: 2013-11-13 08:06:03
by phspaelti
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 850 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)?

Re: Select by Style macro

Posted: 2013-11-13 23:12:22
by martin
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.

Re: Select by Style macro

Posted: 2013-11-14 00:36:24
by phspaelti
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