How to select text without color?

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

How to select text without color?

Post by js » 2012-02-25 03:47:34

From a text with some parts marked with a color attribute, how can I select the rest, without a color attribute. (How can I select black text?)

User avatar
Hamid
Posts: 731
Joined: 2007-01-17 03:25:42

Re: How to select text without color?

Post by Hamid » 2012-02-25 04:38:39

If the colour attribute is the same and not a part of a defined style, select all the text with that colour attribute (from the Statusbar color tag).
Then from the Edit menu apply Select:Inverse Selection.

js
Posts: 229
Joined: 2007-04-12 14:59:36

Re: How to select text without color?

Post by js » 2012-02-25 06:01:08

Yes. But if there are many colors and let's say you don't want to find out how many and which ones. If all you want is "black" text. How about that?

User avatar
Hamid
Posts: 731
Joined: 2007-01-17 03:25:42

Re: How to select text without color?

Post by Hamid » 2012-02-25 06:21:30


js
Posts: 229
Joined: 2007-04-12 14:59:36

Re: How to select text without color?

Post by js » 2012-02-25 12:11:30

It looks indeed as if the commands necessaryfor doing a macro capable of selecting black text are being used in this other macro by Kino. Thank you.

Þorvarður
Posts: 236
Joined: 2012-12-19 05:02:52

Re: How to select text without color?

Post by Þorvarður » 2012-12-21 21:50:10

Hamid wrote:Try Kino's Select by Color macro:
http://www.nisus.com/forum/viewtopic.php?f=18&t=4151
Here is another much better macro by Kino that does exactly what the OP asked for. I'm not sure whether it belongs to the macros that originally come with NWP. I hope it is not redundant. Therefore I post it here. It's called "SelectSameOrOtherColor".


### Select Same or Different Color ###

# Select all text portions having or not having the same color as that of the insertion point.

# If the insertion point is at the very end of a text object, the macro uses Typing Attributes, which may not coincide with what the user expects.

Require Pro Version 1.2
$doc = Document.active
$sel = TextSelection.active
if $sel == undefined
exit
elsif $sel.location == $sel.text.length
$attr = $sel.displayTypingAttributes
else
$attr = $sel.text.displayAttributesAtIndex $sel.location
end
$activeColor = $attr.textColor
$sameColor = $otherColors = Array.new

foreach $text in $doc.allTexts
if $text.length
$i = 0
while $i < $text.length
$attr = $text.displayAttributesAtIndex $i
$range = $text.rangeOfDisplayAttributesAtIndex $i
$sel = TextSelection.new $text, $range
if $attr.textColor == $activeColor
$sameColor.appendValue $sel
else
$otherColors.appendValue $sel
end
$i = $range.bound
end
end
end

$same = 'Same Color'
$other = 'Other Colors'
$color = Prompt 'Select text portions in...', '', $same, $other
if $color == $same
$doc.setSelections $sameColor
else
$doc.setSelections $otherColors
end

### end of macro ###

Post Reply