"Complete List" Macro

Get help using and writing Nisus Writer Pro macros.
Groucho
Posts: 497
Joined: 2007-03-03 09:55:06
Location: Europe

Re: "Complete List" Macro

Post by Groucho »

js wrote:So I know now how to insert Page Breaks with a macro, but not how to insert sections breaks.
You can't actually insert a section break with a find/replace process, js. A section break, unlike a page break, involves much more than inserting a simple rtf tag. Headers and footers must be defined, and also page numbering, page size and orientation and a number of other settings. If you are interested in replacing a section break for every occurrence of a preinserted tag, like <br>, you might find this macro interesting.

Code: Select all

# This macro will replace a predefined, unique tag or placeholder with a section break. This works much like Find and Replace with PowerFind Pro enabled, and makes up for the lack of a regular expression representing a section break.

# INSTRUCTIONS
# 1. First insert a unique placeholder (e.g., <br>) wherever you want a section break to occur in your document. This can be done manually or, better, using “Find and Replace”.
# 2. Run the macro.
# 3. When prompted, choose a section break type (next page, odd page, even page or same page) and click OK.
# 4. When prompted again, type in the tag (Case sEnsITive). PowerFind Pro expressions are recognized.
# 5. Click OK.
#===============================================#


$tag = Prompt Input 'Type in the section break placeholder.'

$break = Prompt Options "Choose a Section Break type.", "", "OK", "Next Page", "Odd Page", "Even Page", "Same Page"

Select All
Select Start

# While Find $tag, '' # Disables PowerFind Pro regular expressions. If enabled, comment out the following line.
While Find $tag, 'E'
	if $break == "Next Page"
	Insert:Section Break:Next Page
	elsif $break == "Odd Page"
	Insert:Section Break:Odd Page
	elsif $break == "Even Page"
	Insert:Section Break:Even Page
	elsif $break == "Same Page"
	Insert:Section Break:Same Page
	end
end
It's a bit spartan, as I wrote it a long time ago for my personal use — it has worked flawlessly so far, though.

Greetings, Henry.
Kino
Posts: 400
Joined: 2008-05-17 04:02:32

Re: "Complete List" Macro

Post by Kino »

js wrote:If I add a section break from the insert menu, and paste it into a find window (in Regex mode) what it actually inserts is \f, the same as a page break.
That is not exactly the same as what I described but yours is better and does work for me. Make sure that Replace Attributes is checked in the Find panel. Curiously, regardless of the kind of section break inserted in the replace field, it works always as Section Break (Same Page) but that would be rather desirable for your purpose, I guess.
With that little modification I get a list of words with paragraph references. But I use other meaningful references. […] I guess it would mean producing a hash like […]
Yes, that would be the easiest way. Assuming all those references consist of a single word, you can convert paragraph numbers to references by adding the following code at the very end of the macro.

Code: Select all

$refs = $doc.text.findAll '^\S+', 'E'
$numToRef = Hash.new
foreach $ref in $refs
	$numToRef{$ref.text.paragraphNumberAtIndex($ref.location)} = $ref.substring
end

$exclude = '\d+\Q' & $freqSep
$exclude &= '\E|\Q' & $openingFreq
$exclude &= '\E\d+\Q' & $closingFreq
$exclude &= '\E'
Find All $exclude, 'E'
Menu 'Edit:Select:Invert Selection'  # If you are running NW Pro with localized interface, you have to translate the command path.
Find All in Selection '\d+', 'E'
$nums = $WordList.textSelections

foreach $num in reversed $nums
	$num.text.replaceInRange $num.range, $numToRef{$num.substring}
end
Groucho wrote:You can't actually insert a section break with a find/replace process, js.
That had been true until the release of the version 1.3…
js
Posts: 259
Joined: 2007-04-12 14:59:36

Re: "Complete List" Macro

Post by js »

Great. that macro works perfectly well for me. Thank you Kino, and also Groucho.

I would suggest that "Insert pagebreak" and "Insert Section break" are documented in the Nisus Macro Refeeence.
Post Reply