Macro to create new file from a template

Get help using and writing Nisus Writer Pro macros.
Post Reply
User avatar
loulesko
Posts: 89
Joined: 2008-01-20 11:08:35
Location: California
Contact:

Macro to create new file from a template

Post by loulesko » 2017-02-13 18:53:18

Hi there - tried below to get Nisus to create a new untitled document based on the name template, but all it does is open the dot file for editing. Any help greatly appreciated.

Thanks
Lou

Code: Select all

$templatePath =  "~/Documents/Nisus/Templates/Manuscript.dot"
$opt = Hash.new('NewFile')
Document.openWithOptions $templatePath, $opt

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

Re: Macro to create new file from a template

Post by phspaelti » 2017-02-13 19:43:44

Hi Lou,
if you have the template among your templates in the Document Manager the following will work:

Code: Select all

Open From Document Manager:Templates:Manuscript.dot
philip

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

Re: Macro to create new file from a template

Post by phspaelti » 2017-02-13 19:54:36

And now looking at your example, I think you need to fix your code as follows:

Code: Select all

$templatePath =  "~/Documents/Nisus/Templates/Manuscript.dot"
$opt = Hash.new('NewFile', @true)
Document.openWithOptions $templatePath, $opt
In other words, the $opt is supposed to be a hash, which means it's supposed to be a list of pairs where the keys ("NewFile", etc.) are matched to truth values @true, or @false.

PS: This code might also need a sandbox permission
philip

User avatar
loulesko
Posts: 89
Joined: 2008-01-20 11:08:35
Location: California
Contact:

Re: Macro to create new file from a template

Post by loulesko » 2017-02-13 22:46:32

Hi Philip,

You were correct, the hash did need to be a pair with @true. You fixed my macro, and I learned something new so this is actually a double thanks to you. Also, it did not need sandbox permission.

have a great day,
Lou

Post Reply