Type Text vs Type Attributed Text

Get help using and writing Nisus Writer Pro macros.
Post Reply
credneb
Posts: 187
Joined: 2007-03-28 07:30:34

Type Text vs Type Attributed Text

Post by credneb »

Greetings.

The macro reference states:
Type Text text
Replaces the currently selected text with the text provided. The inserted text uses the attributes that were applied to the selected text.

Type Attributed Text text
....The inserted text will have the attributes that are applied to the argument in the macro itself.

However, using the Type Text statement in the following macro (abbreviated, which converts 2-byte Japanese characters to 1-byte equivalents), all attributes are removed from the text -- so red text goes black and superscript/subscript attributes are stripped.

Using the Type Attributed Text statement retains the attributes in the original text. But, there are no attributes "applied to the argument in the macro itself."

If the documentation isn't wrong, why isn't Type Text the correct command?

[code]$sel = $doc.selectedSubtext
$len = $sel.length
If $len < 1
Prompt "Select some text first."
Exit
End

$map = Hash.new
$map{'A'} = 'A'
$map{'B'} = 'B'
$map{'C'} = 'C'
$map{'0'} = '0'
$map{'1'} = '1'
$map{'2'} = '2'
$map{'3'} = '3'
$map{'4'} = '4'

$range = Range.new(0, $len)
$sel.transliterateInRange($range, $map)
Type Attributed Text $sel[/code]

Cliff
User avatar
phspaelti
Posts: 1313
Joined: 2007-02-07 00:58:12
Location: Japan

Re: Type Text vs Type Attributed Text

Post by phspaelti »

Hello Cliff,
I don't know that the "documentation isn't wrong". But what you are seeing is the difference between using a variable and a literal. If you use Type Attributed Text with a literal, it will apply the attributes that are applied to the literal in the macro. However if you are using a variable the command applies the attributes that are applied to the text held in the variable.

And as a side note: You are aware that you could just transliterate the selection in place, without needing to copy it into a variable and then typing the variable back into the document? The command would look like this:

Code: Select all

$sel = $doc.textSelection
$sel.text.transliterateInRange($sel.range, $map)
This approach will, as a matter of course, keep the attributes in the document. It won't keep the selection. If you want the selection to get specific attributes, you could re-select it, and then apply the wanted attributes with menu commands. For example

Code: Select all

$sel = $doc.textSelection
$sel.text.transliterateInRange($sel.range, $map)
$doc.setSelection $sel
Size:14
Text Color:Red
Bold
philip
credneb
Posts: 187
Joined: 2007-03-28 07:30:34

Re: Type Text vs Type Attributed Text

Post by credneb »

Hello, Philip.

Thank you for your help.

I was not aware that

$sel.text.transliterateInRange($sel.range, $map)

was valid, and have changed my macro. In the process, (prompted by .textSelection) I learned I was using a deprecated command.

And I have been re-reading the lang ref in the process about literals and interpolated variables.

Thanks again.
Post Reply