Breaking a Large Nissus Document into Separate Documents

Have a problem? A question? This is the place for answers from other Express users.
Post Reply
samuelmuindi
Posts: 15
Joined: 2005-01-18 15:38:02

Breaking a Large Nissus Document into Separate Documents

Post by samuelmuindi » 2007-09-03 12:06:43

I have a very large Nissus document that I would like to break up into smaller files based on manual line breaks. In other words, this very big document has sections delineated by these inserted line breaks. The sections are also marked with an "•".

So ideally I would like find a way to have Nissus find each "line break command + •" and then export the text between that marker and the next "line break command + •" into a new Nissus document.

Is this possible?

Many thanks

User avatar
martin
Official Nisus Person
Posts: 4290
Joined: 2002-07-11 17:14:10
Location: San Diego, CA
Contact:

Post by martin » 2007-09-04 14:24:04

In Nisus Writer Express you'll need to do the work manually, eg: use a search expression to find these breaks, copy-paste the content to a new file, and save it yourself.

In Nisus Writer Pro it would be possible to create a macro to do the work for you I think. I'd need to know exactly what you mean when you say "manual line breaks". Are these page breaks, newlines, or soft returns?

samuelmuindi
Posts: 15
Joined: 2005-01-18 15:38:02

Reply

Post by samuelmuindi » 2007-09-17 11:58:01

I'm using Nisus Writer Express, but I would gladly buy a copy of Nisus Writer Pro to avoid having to do this work manually.

By "manual line breaks" a do mean "page breaks."

Thanks so much.

User avatar
martin
Official Nisus Person
Posts: 4290
Joined: 2002-07-11 17:14:10
Location: San Diego, CA
Contact:

Post by martin » 2007-09-17 16:45:09

The following macro should do what you want. If your file was saved as "file.rtf" then it will create "file - part 1.rtf", "file - part 2.rtf", etc. You should be warned that the macro will overwrite these "part N" files if they already exist, so be careful.

Code: Select all

$docPartPrefix = '•'

# gather start information
$filePath = Document Property ‘File Path’
If '' == $filePath
	Prompt 'The document must be saved before it can be split.'
	exit
End
$partCount = 0
$partStart = 1
Set Selection 1, 0 # Move to the start of the document

# We split on every break followed by a bullet character
While true
	# find the next break
	$isFound = Find "\\x0C$docPartPrefix", ‘E-W’
	If false == $isFound
		# still want to save the last document part, if not already done
		$docLim = Selected Storage Length
		If $partStart >= $docLim
			exit "Successfully split and saved the document to $partCount separate files."
		End
		$docLim += 1
		Set Selection $docLim, 0
	End
	$foundStart = Selection Location
	$foundLength = Selection Length
	
	# extract the document part
	$partLen = $foundStart
	$partLen -= $partStart
	Set Selection $partStart, $partLen
	$partContent = Read Selection
	Set Selection $foundStart, $foundLength
	
	# construct the part's file name
	$partPath = $filePath
	Begin Perl
		$partPath =~ s/(\.[a-z0-9]{3,4})?$//i;
		$partPath .= ' - part ' . ($partCount + 1) . '.rtf';
	End
	
	# save the part to another file
	$partRTF = Encode RTF $partContent
	$isWritten = Write to File $partRTF, $partPath
	If false == $isWritten
		die "Could not write the document part to '$partPath'. Aborting the macro."
	End
	
	$partStart = $foundStart
	$partStart += 1 # do not include the break
	$partCount += 1
End

samuelmuindi
Posts: 15
Joined: 2005-01-18 15:38:02

Error Message

Post by samuelmuindi » 2007-09-18 12:14:30

Thanks so much for this, but when I tried to run the Macro I got the message

There was an error on line 23 in the macro: Invalid variable name "docLim+".

Thanks

User avatar
martin
Official Nisus Person
Posts: 4290
Joined: 2002-07-11 17:14:10
Location: San Diego, CA
Contact:

Post by martin » 2007-09-18 13:28:09

It sounds like you're trying to run the macro in NWP 1.0. This macro requires version 1.0.1. Sorry I did not mention that.

Also, as you are no doubt copy-pasting the macro text from Safari, you will need to replace the non-breaking space characters with regular spaces. Perl does not accept them. Only the following lines need modification:

Code: Select all

Begin Perl 
	$partPath =~ s/(\.[a-z0-9]{3,4})?$//i; 
	$partPath .= ' - part ' . ($partCount + 1) . '.rtf'; 
End
Sorry for the extra work- next time I will just post a link to a macro file which does not have this issue.

samuelmuindi
Posts: 15
Joined: 2005-01-18 15:38:02

Same Error Message

Post by samuelmuindi » 2007-09-18 14:24:52

Sorry, I'm still getting that same error message even though I installed the most recent version NWP. I also think that I changed the code as you instructed but I confess that I'm having trouble making sure.

I really appreciate your help with this.

Thanks

User avatar
martin
Official Nisus Person
Posts: 4290
Joined: 2002-07-11 17:14:10
Location: San Diego, CA
Contact:

Post by martin » 2007-09-18 14:32:24

Here's the macro saved as a Nisus Writer Macro file. Running it in NWP 1.0.1 I have no trouble.

samuelmuindi
Posts: 15
Joined: 2005-01-18 15:38:02

Outstanding

Post by samuelmuindi » 2007-09-19 09:30:13

Thanks so much, this really did the trick.

One final question. I'm a registered Nisus Express user, but NWP seems to be more geared to my needs. So at this point I'm try to decide whether to make good on my promise and buy NWP or to purchase the Nisus Express upgrade.

Any thoughts?

THanks again.

User avatar
scottwhitlock
Posts: 174
Joined: 2004-10-26 07:10:40
Location: Tucson, AZ
Contact:

Post by scottwhitlock » 2007-09-19 10:50:56

Go for the NWPro upgrade. It will serve you better in the long run, especially if you need customized macros to do work for you. Also, if you ever need to work on long documents, its bookmarking, TOC, and indexing are indispensable. And there's nothing in Express that is not in Pro, however there is a lot in Pro that is not in Express. It's well worth the $15 difference.

Scott
MacBook Pro 15
2.66 Ghz Core i7
8GB RAM
10.8.3
NWP 2.0.4
iPad 3

samuelmuindi
Posts: 15
Joined: 2005-01-18 15:38:02

Sold

Post by samuelmuindi » 2007-09-19 11:39:02

You've convinced me.

For the record, I had originally tried to split this document using Word, but it choked on the size of the document (1100 single spaced pages) and crashed. NWP, on the other hand, spat out 850 separate text file documents in about 4 minutes.

Post Reply