joining files with page breaks when needed

Get help using and writing Nisus Writer Pro macros.
Post Reply
ThosGreen
Posts: 3
Joined: 2021-09-15 03:28:09

joining files with page breaks when needed

Post by ThosGreen »

I wish to join files as chapters, so that each new file starts on an odd (right-hand, recto) page. I have tried to modify Kino's Join Files macro so that as each file is added, if the last page is odd-numbered then a page break is inserted before the next file is added, but I have been unable to find the page number of the last page ...

I have been using

Code: Select all

newTextObj.pageNumberAtIndex [i]index[/i]
but whatever I do with index, I get nothing returned. I have tried setting index to hard-coded values like 3, and also computing the length of the text object - no luck.

Could anyone give me advice on this?

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

Re: joining files with page breaks when needed

Post by phspaelti »

Well, pagination is this thing. Nisus needs to calculate the page layout. And before you include pages in a document so Nisus can do that, there won't actually be any pages. As the macro language documentation says, for new text objects like the one you are working with, you will just get undefined as the answer.

Your best bet would be to write a separate macro, that you could run after you have joined the files and created the document. I'm assuming that you already are setting the relevant headings to always start a new page, and that what you are looking for is something that will insert a blank page every time such a heading is on an even page.

That macro would look something like this:

Code: Select all

$doc = Document.active
$headingStyle = $doc.styleWithName ("Heading 1")
while Find($headingStyle, "-W")
  $sel = TextSelection.active
  $pageNum = $doc.text.pageNumberAtIndex $sel.location
  if ($pageNum % 2) == 0
    $doc.text.insertAtIndex $sel.location, "\x0C\n"
  end
end
I have given this only a cursory test.
philip

ThosGreen
Posts: 3
Joined: 2021-09-15 03:28:09

Re: joining files with page breaks when needed

Post by ThosGreen »

Very effective - and very fast turnaround - gold star there!

Many thanks.

Post Reply