Reply to topic  [ 3 posts ] 
Find colored text 
Author Message

Joined: 2011-03-23 07:39:53
Posts: 1
I've looked through the manual but can't find it. Is there a way to find a words or characters having colored text?
Any help appreciated.


2011-03-23 07:42:53
Profile

Joined: 2008-05-17 04:02:32
Posts: 400
If you want to find and select all texts in the same colour (manually applied, not defined in a style), put the insertion point somewhere in a text in that colour and choose ‘Select All’ from the pull-down menu (click on a coloured circle) in the status bar at the bottom of the document window.
Attachment:
SelectAllColor.png
SelectAllColor.png [ 20.07 KiB | Viewed 2433 times ]

If you want to find and select all texts in different colours, I think the macro below will do the job.
Code:
 Require Pro Version 1.3
$doc = Document.active
if $doc == undefined
   exit
end

$black = Color.newWithRGBA 0, 0, 0, 1
$white = Color.newWithRGBA 1, 1, 1, 1
$colors = Hash.new
$samples = Array.new
$TC = Cast to String '[text] '
$BG = Cast to String '[back] '
$HL = Cast to String '[highlight] '
$sep = Cast to String '/'
$showSamples = Cast to String 'Show Samples'
$language = Language.systemLanguage

foreach $text in $doc.allTexts
   $textRanges = Array.new
   if $text.tables.count # then, exclude special texts enclosing tables
      $tableRanges = Array.new
      foreach $table in $text.tables
         $tableRanges.appendValue $table.enclosingTextRange
      end
      $tableRanges.sort
      $i = 0
      foreach $tableRange in $tableRanges
         $range = Range.newWithLocationAndBound $i, $tableRange.location
         $textRanges.appendValue $range
         $i = $tableRange.bound
      end
      $range = Range.newWithLocationAndBound $i, $text.length
   else
      $range = Range.new 0, $text.length
   end
   $textRanges.appendValue $range
   foreach $textRange in $textRanges
      $i = $textRange.location
      while $i < $textRange.bound
         $attr = $text.displayAttributesAtIndex $i
         $range = $text.rangeOfDisplayAttributesAtIndex $i
         $sel = TextSelection.new $text, $range
         if $attr.textColor != $black
            $key = $TC & $attr.textColor.hexTriplet
            $key &= $sep & $attr.textColor.opacity
            if $colors{$key} == undefined
               $colors{$key} = Array.new
               $sample = $key
               Push Target Text $sample
                  Set Text Color $attr.textColor
               Pop Target Text
               $samples.appendValue $sample
            end
            $colors{$key}.appendValue $sel
         end
         if $attr.textBackgroundColor != $white
            $key = $BG & $attr.textBackgroundColor.hexTriplet
            $key &= $sep & $attr.textBackgroundColor.opacity
            if $colors{$key} == undefined
               $colors{$key} = Array.new
               $sample = $key
               Push Target Text $sample
                  Set Background Color $attr.textBackgroundColor
               Pop Target Text
               $samples.appendValue $sample
            end
            $colors{$key}.appendValue $sel
         end
         if Defined $attr.textHighlightColor
            $key = $HL & $attr.textHighlightColor.hexTriplet
            $key &= $sep & $attr.textHighlightColor.opacity
            if $colors{$key} == undefined
               $colors{$key} = Array.new
               $sample = $key
               Push Target Text $sample
                  Set Highlight Color $attr.textHighlightColor
               Pop Target Text
               $samples.appendValue $sample
            end
            $colors{$key}.appendValue $sel
         end
         $i = $range.bound
      end
   end
end

if ! $colors.keys.count
   exit 'No color found, exiting...'
end

$keys = $colors.keys
$keys.sort 'li', $language
$keys.appendValue $showSamples

$keys = Prompt Checkboxes '', '', '', $keys
if ! $keys.count
   exit # nothing checked
end

if $keys.lastValue == $showSamples
   $showSamples = true
   $keys.pop
end

if $keys.count
   $sels = Array.new
   foreach $key in $keys
      $sels.appendValuesFromArray $colors{$key}
   end
   $doc.setSelections $sels
end

if $showSamples == true
   $LF = Cast to String "\n"
   $samples.sort 'li', $language
   $samples = $samples.join $LF
   Document.newWithText $samples
end
Attachment:
SelectByColor_20110324_nwm.zip [4.95 KiB]
Downloaded 235 times

In either case, if you need looking at each one of selected texts, adding Bookmarks to them (Insert:Bookmarks:Add Bookmark) and visiting them one by one from Navigator (View:Show Navigator and switch to Bookmarks from Table of Content) would be handy.


2011-03-23 08:17:23
Profile
Official Nisus Person
User avatar

Joined: 2002-07-11 17:14:10
Posts: 4251
Location: San Diego, CA
Kino's macro and tip about the color tag's "select all" menu are a good way to go. Another option is to use attribute sensitive search:

1. Open the Find and Replace dialog.
2. By the "find what" field, click the gear icon to insert a PowerFind bubble for Wild Card > AnyText.
3. Select that bubble and use the formatting menus (eg: Format > Text Color > Red).
(Applying formatting to the bubble should automatically turn on the "attribute sensitive" option just below)
4. Use the Find Next / Find All buttons as you normally would.


2011-03-23 12:07:05
Profile WWW
Display posts from previous:  Sort by  
Reply to topic   [ 3 posts ] 

Who is online

Users browsing this forum: Majestic-12 [Bot] and 6 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
cron
Powered by phpBB® Forum Software © phpBB Group
Designed by ST Software