Select All in Highlight

Get help using and writing Nisus Writer Pro macros.
Post Reply
js
Posts: 259
Joined: 2007-04-12 14:59:36

Select All in Highlight

Post by js »

There is no standard menu "Select All in Highlight", though this can by done manually ( in the Menu with the mini icons on the bottom of the page. (Wich appears if the cursor is inside highlighted text). I wonder if it is possible to create a macro that selects All in Highlight.
User avatar
phspaelti
Posts: 1313
Joined: 2007-02-07 00:58:12
Location: Japan

Re: Select All in Highlight

Post by phspaelti »

Here is a quick example of how to do this. The ugly bit is that it prompts the user with color objects which are hard to read.
Attachments
Select All in HighLight.nwm
(7.28 KiB) Downloaded 126 times
philip
Þorvarður
Posts: 410
Joined: 2012-12-19 05:02:52

Re: Select All in Highlight

Post by Þorvarður »

js wrote: 2023-08-20 09:15:01 [Is it] possible to create a macro that selects All in Highlight.
I think Kino's macro "SelectByColor" does exactly that.

phspaelti wrote: 2023-08-20 09:49:10 The ugly bit is that it prompts the user with color objects which are hard to read.
I think Kino has a nice solution to this problem. He offers the option "Show Samples".
See: <http://www.nisus.com/forum/viewtopic.php?f=18&t=4151>

-------

In the Nisus Macro Reference I found this command:
.textHighlightColor
and—not surprisingly— no examples of how to use this command. :–(

What am I supposed to put in front of the the dot?
User avatar
phspaelti
Posts: 1313
Joined: 2007-02-07 00:58:12
Location: Japan

Re: Select All in Highlight

Post by phspaelti »

Hey Þorvarður,
Þorvarður wrote: 2023-08-20 12:06:02
js wrote: 2023-08-20 09:15:01 [Is it] possible to create a macro that selects All in Highlight.
I think Kino's macro "SelectByColor" does exactly that.
I don't know that one. Though Color and Highlight (color) are not really the same thing. The former affects the text/font, while the latter is a special marking attribute.
Þorvarður wrote: 2023-08-20 12:06:02
phspaelti wrote: 2023-08-20 09:49:10 The ugly bit is that it prompts the user with color objects which are hard to read.
I think Kino has a nice solution to this problem. He offers the option "Show Samples".
See: <http://www.nisus.com/forum/viewtopic.php?f=18&t=4151>
To be honest I was just being lazy. It would have required a lot of extra work on my part, and I just didn't feel like spending the time on that kind of thing. Kino obviously worked hard to make some very well worked out macros.
Þorvarður wrote: 2023-08-20 12:06:02 In the Nisus Macro Reference I found this command:
.textHighlightColor
and—not surprisingly— no examples of how to use this command. :–(

What am I supposed to put in front of the the dot?
Well, you find that command (actually a property, but who's keeping track) under the attribute object, which means you need an attribute object before the dot. You can get attribute objects in any of half a dozen different ways. For example:

Code: Select all

$attr = Attributes.selectedAttributes
prompt $attr.textHighlightColor
If your current selection includes some highlight this will show you the color (in color code form).
The most obvious/useful way to work with attributes is to use, what I call, a "Kino-loop"; basically cycle though the whole document attribute section by attribute section:

Code: Select all

$doc = Document.active
$loc = 0
while $loc < $doc.text.length
   $range = $doc.text.rangeOfAttributesAtIndex $loc
   ...
   $loc = $range.bound
end
Then you can process the attributes in some way inside the loop.
You may need to use .rangeOfDisplayAttributesAtIndex instead, depending on the purpose.
philip
js
Posts: 259
Joined: 2007-04-12 14:59:36

Re: Select All in Highlight

Post by js »

Thank you both for your help. The macro sent by Philip can in fact do more than I need, but there is a problem:

As to more than I need:
I use highlights by defining one color only which I insert by a macro. To find all highlights created by that macro I just had to adapt Philip's Macro. Instead of the lines providing user choice I just inserted what I defined as $myHilite, like this:

Code: Select all

if $highLights.keys.count
$myHilite = Color.newWithHexTriplet 0x0FFFFA3
$doc.setSelection $highLights{$myHilite}
...
As to the problem:
The macro works fine with contiguous text. But I need it also with a table which has some of its elements marked with that highlight. While the menu at the bottom of the page selects the elements as expected, the macro does not. Can you see why?
User avatar
phspaelti
Posts: 1313
Joined: 2007-02-07 00:58:12
Location: Japan

Re: Select All in Highlight

Post by phspaelti »

js wrote: 2023-08-20 13:42:26 As to the problem:
The macro works fine with contiguous text. But I need it also with a table which has some of its elements marked with that highlight. While the menu at the bottom of the page selects the elements as expected, the macro does not. Can you see why?
Yes, of course. My macro crudely uses $doc.text. If one wants to find highlight in all text areas of the document one needs to use $doc.allTexts and loop through each of the text objects separately. Fortunately this does not require a huge change.
I'm submitting a changed version of my macro, and will let you do the adjustments for your purpose :wink:
Attachments
Select All in HighLight.nwm
(7.42 KiB) Downloaded 122 times
philip
js
Posts: 259
Joined: 2007-04-12 14:59:36

Re: Select All in Highlight

Post by js »

Thank you Philip. That works fine now!
Þorvarður
Posts: 410
Joined: 2012-12-19 05:02:52

Re: Select All in Highlight

Post by Þorvarður »

phspaelti wrote: 2023-08-20 13:08:08 that command (actually a property, but who's keeping track)
I'm all for using the right terminology, so thanks for reminding me, and thanks for the examples.

I think one difference to Kino's macro is that his macro enables one to find and select any Highlighted and any Background color as well as colored text in the document. No part of the document needs to be first selected.
1.png
1.png (26.03 KiB) Viewed 1863 times

The "samples":
2.png
2.png (23.39 KiB) Viewed 1863 times

I just thought I should point this out, as this might perhaps be useful for someone else who needs to work with Highlight and Background colors.
Post Reply