Page 1 of 1

Macro to create new file from a template

Posted: 2017-02-13 18:53:18
by loulesko
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

Re: Macro to create new file from a template

Posted: 2017-02-13 19:43:44
by phspaelti
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

Re: Macro to create new file from a template

Posted: 2017-02-13 19:54:36
by phspaelti
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

Re: Macro to create new file from a template

Posted: 2017-02-13 22:46:32
by loulesko
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