Reply to topic  [ 18 posts ]  Go to page Previous  1, 2
"Complete List" Macro 
Author Message

Joined: 2007-03-03 09:55:06
Posts: 494
Location: Europe
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:
# 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.


2009-07-18 07:07:48
Profile

Joined: 2008-05-17 04:02:32
Posts: 400
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.

Quote:
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:
$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…


2009-07-18 08:10:41
Profile

Joined: 2007-04-12 14:59:36
Posts: 229
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.


2009-07-18 15:42:38
Profile
Display posts from previous:  Sort by  
Reply to topic   [ 18 posts ]  Go to page Previous  1, 2

Who is online

Users browsing this forum: Yahoo [Bot] 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