“Split Document” macro to respect New File settings

Get help using and writing Nisus Writer Pro macros.
Post Reply
adryan
Posts: 561
Joined: 2014-02-08 12:57:03
Location: Australia

“Split Document” macro to respect New File settings

Post by adryan »

G’day, all

I want to modify Kino’s “Split Document” macro so that the destination files respect my Nisus New File settings. For example, as it stands at the moment, the macro produces documents whose Page Setup settings (such as paper size) differ from those in my Nisus New File.

I have tried inserting “Document.new” and “Document.openWithOptions” commands, together with appropriate parameters, towards the end of the final loop in the macro, before the data is written to the destination file. I have tried many things, but nothing works. I thought that using “NewFile” as a hash key would work with the second of these commands, but it seems I don’t really understand the operation of hash objects in this connection.

Can anyone help?

Cheers,
Adrian
MacBook Pro (M1 Pro, 2021)
macOS Ventura
Nisus Writer user since 1996
User avatar
phspaelti
Posts: 1313
Joined: 2007-02-07 00:58:12
Location: Japan

Re: “Split Document” macro to respect New File settings

Post by phspaelti »

Hello Adrian,

what macro are you referring to? The macro at this address http://www2.odn.ne.jp/alt-quinon/files/NWPro/file/?
That macro was probably written at a time when the options for saving files were somewhat limited, as it writes out the file pieces as data. You'd have to actually rewrite that whole section to get it to use the Document.new command.
philip
User avatar
phspaelti
Posts: 1313
Joined: 2007-02-07 00:58:12
Location: Japan

Re: “Split Document” macro to respect New File settings

Post by phspaelti »

adryan wrote:I have tried inserting “Document.openWithOptions” commands, together with appropriate parameters, … I have tried many things, but nothing works. I thought that using “NewFile” as a hash key would work with the second of these commands, but it seems I don’t really understand the operation of hash objects in this connection.
Independent of the other question, this is how you would use the "Document.openWithOptions" command:

Code: Select all

$options = Hash.new ("NewFile", @true)
Document.openWithOptions $filepath, $options
Assuming that $filepath points at a valid existing document, this will open that document as a template. It will not be using the "Nisus New File" settings. It will be using whatever settings are set in that document.

The way I understand you, this is not what you are looking for.
philip
adryan
Posts: 561
Joined: 2014-02-08 12:57:03
Location: Australia

Re: “Split Document” macro to respect New File settings

Post by adryan »

G'day, Philip et al

Thanks for looking at this for me.

The macro on the Web site you cited is dated 2009-06-27. The version I have is dated 2009-07-02. The differences are fairly trivial, but I attach the version I have.

I was using code very similar to the fragment you gave — slightly different syntax in the Macro Language Reference. So perhaps my understanding was not that amiss after all.

You are right that the file must already exist in order for the "Document.openWithOptions" command to work. Comparing what you say with the Macro Language Reference, I think I have been misled by the latter. The "NewFile" option may open a document in an Untitled window, but there the resemblance to a proper Nisus New File document seems to end. Placing the command after the "File.writeDataToPath" command (to ensure it works on an existing file) does not reproduce the Page Setup settings in my Nisus New File template.

The "New" command uses the Nisus New File template, as does the "Document.new 'true'" command. So it would be nice to insert one of them into the macro.

But I can't quite see how to save the resultant document to the $filePath produced by the macro. Once this were done, presumably the "File.writeDataToPath" command would overwrite the contents while preserving such things as window size and Page Setup.

Cheers,
Adrian
Attachments
Split Document.nwm
(35.44 KiB) Downloaded 776 times
MacBook Pro (M1 Pro, 2021)
macOS Ventura
Nisus Writer user since 1996
User avatar
phspaelti
Posts: 1313
Joined: 2007-02-07 00:58:12
Location: Japan

Re: “Split Document” macro to respect New File settings

Post by phspaelti »

Here is my modification of the macro using "Document.new" (and also making it compatible with Sandbox access).
SplitDocument_new.nwm
(24.17 KiB) Downloaded 917 times
One important difference of using the "Document.new" command is that you get the "light show", since each part document will be created, saved and closed.
Hope this helps
philip
adryan
Posts: 561
Joined: 2014-02-08 12:57:03
Location: Australia

Re: “Split Document” macro to respect New File settings

Post by adryan »

G’day, Philip et al

Thank you very much for that. I now see how to save the new document appropriately. It seems I hadn’t appreciated the “.setActive” command sufficiently.

The "light show" doesn’t bother me unduly. After all, the content of my documents is just so interesting, and I can speed-read. (Just kidding about the speed-reading.)

It turns out that Kino’s macro doesn’t actually strip out the Page Breaks and Section Breaks from the destination documents. I have rectified this by inserting the following line before the “Save As $filePath” line:–

Replace All '\f', '', 'E'

The macro now does what I want. I have attached it here, with appropriate attribution.

Thanks again, Philip.

Cheers,
Adrian
Attachments
SplitDocument_new.nwm
(26.55 KiB) Downloaded 801 times
MacBook Pro (M1 Pro, 2021)
macOS Ventura
Nisus Writer user since 1996
Post Reply