Type Text vs Type Attributed Text
Page 1 of 1

Author:  credneb [ 2017-01-13 18:56:11 ]
Post subject:  Type Text vs Type Attributed Text


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."

$map =
$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 =, $len)
$sel.transliterateInRange($range, $map)
Type Attributed Text $sel[/code]


Author:  phspaelti [ 2017-01-14 04:36:58 ]
Post subject:  Re: Type Text vs Type Attributed Text

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:
$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
$sel = $doc.textSelection
$sel.text.transliterateInRange($sel.range, $map)
$doc.setSelection $sel
Text Color:Red

Author:  credneb [ 2017-01-14 23:04:33 ]
Post subject:  Re: Type Text vs Type Attributed Text

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.

Page 1 of 1 All times are UTC - 8 hours
Powered by phpBB® Forum Software © phpBB Group