Page 1 of 1

Variable substitution

Posted: 2019-07-06 03:50:12
by belgianreader
Hi

Is it possible in NWP to do something like the following?

I would like to include an in-line variable to hold for example, the current text's font name, something like this "This is the <current-font-name> font" but can't find much about built-in variables?

Thanks

Re: Variable substitution

Posted: 2019-07-06 04:47:48
by phspaelti
This type of thing can be done via the macro language. The detailed features of the macro language can be found in the Macro Language Reference which is in the Help menu. For example you can get the name of the current font like this:

Code: Select all

$sel = TextSelection.active
$currentFont = $sel.displayTypingAttributes.fontName
prompt $currentFont
If you want the macro to insert this info into the text at the current selection instead, you can replace the last line with the following:

Code: Select all

$sel.text.insertAtIndex $sel.bound, "This is the $currentFont font"

Re: Variable substitution

Posted: 2019-07-06 07:04:46
by belgianreader
Thanks Philip, I'll give that a go.

Nick

Re: Variable substitution

Posted: 2019-07-16 13:30:29
by martin
Depending on what you're doing, you might also check out custom document properties, which can act like variables. They are simpler than macros (though of course are also more limited). You can view and edit custom properties using the menu File > Properties. Once you've established some properties you can insert their value into your document's text using the menu Insert > Document Property > Custom Property.