Variable substitution

Everything related to our flagship word processor.
Post Reply
belgianreader
Posts: 4
Joined: 2011-04-26 01:33:36

Variable substitution

Post by belgianreader » 2019-07-06 03:50:12

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

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

Re: Variable substitution

Post by phspaelti » 2019-07-06 04:47:48

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

belgianreader
Posts: 4
Joined: 2011-04-26 01:33:36

Re: Variable substitution

Post by belgianreader » 2019-07-06 07:04:46

Thanks Philip, I'll give that a go.

Nick

martin
Official Nisus Person
Posts: 4586
Joined: 2002-07-11 17:14:10
Location: San Diego, CA
Contact:

Re: Variable substitution

Post by martin » 2019-07-16 13:30:29

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.

Post Reply