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 »

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: 1313
Joined: 2007-02-07 00:58:12
Location: Japan

Re: Variable substitution

Post 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"
philip
belgianreader
Posts: 4
Joined: 2011-04-26 01:33:36

Re: Variable substitution

Post by belgianreader »

Thanks Philip, I'll give that a go.

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

Re: Variable substitution

Post 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.
Post Reply