Color attributes 2

Get help using and writing Nisus Writer Pro macros.
Post Reply
Pat
Posts: 28
Joined: 2009-09-04 13:11:25

Color attributes 2

Post by Pat »

Hi again,

I have a few other questions.

1- I would like to know if it is possible to give a color attribute to a string of letters only when that string of letter is ending a word (for the letters "ble" in the word impossible).

2- Is it possible to give different color attributes to each letter of a string without using the "Insert attributed Text" command (for example, in the string "ble" I would like to make the letter b blue, the letter l red and the letter e green).

3- What should I read to get introduce to the basic concepts I need to understand to write more elaborate macros? Is the macro reference enough? The Nisus guide and the Nisus macro reference are well written, but they don't give enough examples to show a beginner how to write more complex macros by himself.

Thank you.
Kino
Posts: 400
Joined: 2008-05-17 04:02:32

Re: Color attributes 2

Post by Kino »

1. You can do something like this.

Code: Select all

Find All 'ble\b', 'E-i'
	# \b: word boundary
	# E: PowerFind Pro mode
	# -i: case sensitive
Menu ':Format:Text Color:Blue'
If you prefer the color object…

Code: Select all

Find All 'ble\b', 'E-i'
$blue = Color.newWithHexTriplet 0x0000FF
Set Text Color $blue
2. How about this?

Code: Select all

$red = Color.newWithHexTriplet 0xFF0000
$green = Color.newWithHexTriplet 0x00FF00
$blue = Color.newWithHexTriplet 0x0000FF

$doc = Document.active
Find All 'ble\b', 'E-i'
	# \b: word boundary
	# E: PowerFind Pro mode
	# -i: case sensitive

$sels = $doc.textSelections  # get current selections

# Find All in Selection 'b'  # This command is unnecessary
Set Text Color $blue

$doc.setSelections $sels  # restore selections

Find All in Selection 'l'
Set Text Color $red

$doc.setSelections $sels  # restore selections

Find All in Selection 'e'
Set Text Color $green
3. It would be much more helpful in mastering Nisus Macro to write, say, 100 macros than to read the Reference 100 times. And I think everyone starts with modifying existing macros so that they fits one's own needs. Also writing macros for inspecting Nisus Macro elements (object, command, property) would be very useful in understanding them. For example, the following shows text selection objects in plain text format.

Code: Select all

Debug.setDestination 'new'
$doc = Document.active
Find All 'ble\b', 'E-i'
$sels = $doc.textSelections
Debug.log $sels
Pat
Posts: 28
Joined: 2009-09-04 13:11:25

Re: Color attributes 2

Post by Pat »

Thank you for your help!
User avatar
martin
Official Nisus Person
Posts: 5228
Joined: 2002-07-11 17:14:10
Location: San Diego, CA
Contact:

Re: Color attributes 2

Post by martin »

The macro reference doesn't have a lot of examples, but Kino's suggest to look at other macros is a good one. Don't forget about the macro repository, as well as Kino's own cache of copious macros.
Post Reply