nisus.com
https://www.nisus.com/forum/

Select by Style macro
https://www.nisus.com/forum/viewtopic.php?f=17&t=5531
Page 1 of 1

Author:  phspaelti [ 2013-11-13 08:06:03 ]
Post subject:  Select by Style macro

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:

Attachment:
Select By Style (new).nwm [18.1 KiB]
Downloaded 212 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)?

Author:  martin [ 2013-11-13 23:12:22 ]
Post subject:  Re: Select by Style macro

Quote:
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.

Quote:
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.

Quote:
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.

Author:  phspaelti [ 2013-11-14 00:36:24 ]
Post subject:  Re: Select by Style macro

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:
$doc = Document.active
$styleNames = $doc.allStyles.arrayByMakingValuesDoCommand 'name'
$styleName = prompt Options 'Choose a style', '', 'Find', $styleNames
$style = $doc.styleWithName($styleName)
Find All $style

Page 1 of 1 All times are UTC - 8 hours
Powered by phpBB® Forum Software © phpBB Group
http://www.phpbb.com/