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
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)?
Select by Style macro
- martin
- Official Nisus Person
- Posts: 5228
- Joined: 2002-07-11 17:14:10
- Location: San Diego, CA
- Contact:
Re: Select by Style macro
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.They are certainly nice macros, but they are not for the faint of heart.
Ah, wonderful– much cleaner! I especially enjoy seeing the use of the "getProperty" command to dynamically loop through the different style types.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
It sounds like a good idea to me, I'll file the suggestion. Thank you Philip.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
Yes, it was great to find a use for thatmartin wrote:I especially enjoy seeing the use of the "getProperty" command to dynamically loop through the different style types.
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. 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