Reply to topic  [ 6 posts ] 
“Split Document” macro to respect New File settings 
Author Message

Joined: 2014-02-08 12:57:03
Posts: 170
Location: Australia
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 (mid-2014)
macOS Sierra 10.12.6
Nisus Writer user since 1996


2016-04-06 21:10:40
Profile
User avatar

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


2016-04-07 02:20:40
Profile
User avatar

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


2016-04-07 02:32:58
Profile

Joined: 2014-02-08 12:57:03
Posts: 170
Location: Australia
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 48 times

_________________
MacBook Pro (mid-2014)
macOS Sierra 10.12.6
Nisus Writer user since 1996
2016-04-07 04:47:53
Profile
User avatar

Joined: 2007-02-07 00:58:12
Posts: 876
Location: Japan
Here is my modification of the macro using "Document.new" (and also making it compatible with Sandbox access).
Attachment:
SplitDocument_new.nwm [24.17 KiB]
Downloaded 44 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


2016-04-07 08:22:50
Profile

Joined: 2014-02-08 12:57:03
Posts: 170
Location: Australia
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 57 times

_________________
MacBook Pro (mid-2014)
macOS Sierra 10.12.6
Nisus Writer user since 1996
2016-04-07 15:54:36
Profile
Display posts from previous:  Sort by  
Reply to topic   [ 6 posts ] 

Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB® Forum Software © phpBB Group
Designed by ST Software