Setting The Style For Unstyled Paragraphs

Get help using and writing Nisus Writer Pro macros.
Post Reply
WolfUK
Posts: 12
Joined: 2007-08-17 14:21:25
Location: Somerset, England

Setting The Style For Unstyled Paragraphs

Post by WolfUK » 2007-08-17 14:46:56

To help me evaluate Nisus Writer Pro I imported a pretty hefty document that I have been working on. It came across pretty well but since it was a Pages document that I exported to RTF and then opened it lost all of the styles that I had defined. This is not a major problem but it would save me a lot of time if I only had to create new styles for headings and a few other items and was then able to designate every other paragraph without a style as being my 'Body' style.

Is this sort of thing possible?
Simon Wolf

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

Post by martin » 2007-08-17 18:27:32

I'm going to guess what you want is possible, but I'm not sure exactly what you're after. What criteria do you want to use for selecting paragraphs that need to have styles applied? You just want to select all paragraphs without any paragraph style and then apply your Body style?

WolfUK
Posts: 12
Joined: 2007-08-17 14:21:25
Location: Somerset, England

Post by WolfUK » 2007-08-17 23:40:53

Yes, exactly right, I was to select all paragraphs without a paragraph style and apply my Body style.
Simon Wolf

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

Post by martin » 2007-08-19 19:48:30

Hi Simon, I'm sorry to say I spoke too soon. There's no way to select all the text in your document that has no paragraph style applied. Does the text you want to apply your style to really have no style applied, or just some generic style like Normal that you don't care for?

WolfUK
Posts: 12
Joined: 2007-08-17 14:21:25
Location: Somerset, England

Post by WolfUK » 2007-08-19 23:51:06

Hi Martin,

There was no style selected at all (as far as I can tell ... maybe because I didn't have a style called Normal nothing was displayed). Anyway, don't worry too much because as I worked through the document checking that everything had come in properly and that it was all laid out properly I added the paragraph styles.

Now, if there was better AppleScript support ... :wink:
Simon Wolf

Kino
Posts: 400
Joined: 2008-05-17 04:02:32

Re: Setting The Style For Unstyled Paragraphs

Post by Kino » 2009-12-20 05:29:53

Thanks to the great improvement of the Nisus Macro language, now we can write such a macro. I'm not using Pages but sometimes I need to do the same thing, for example, when formatting an etext.

Code: Select all

$defaultParagraphStyleName = 'Normal'  # Put an appropriate paragraph style name between the single quotes

Require Pro Version 1.3
$doc = Document.active
if $doc == undefined
	exit  # exit silently
end

$paras = $doc.paragraphStyles
$defaultParagraphStyle = undefined
foreach $para in $paras
	if $para.name == $defaultParagraphStyleName
		$defaultParagraphStyle = $para
		Break
	end
end

if $defaultParagraphStyle == undefined
	exit "You have to create or import \"$defaultParagraphStyleName\" paraagraph style before running this macro, exiting..."
end

$sels = $doc.text.findAll '^\p{Any}', 'E', '-am'  # in the main document body only

foreach $i, $sel in reversed $sels
	if $sel.text.documentContentType != 'body'  # then, $sel is in a table
		$sels.removeValueAtIndex $i
	else
		$attr = $sel.text.attributesAtIndex $sel.location
		if $attr.paragraphStyle != undefined  # then, this paragraph has a style
			$sels.removeValueAtIndex $i
		end
	end
end

if $sels.count
	Push Target Selection $sels
		$defaultParagraphStyle.apply
	Pop Target Selection
else
	exit 'There is no paragraph not having a paragraph style, exiting...'
end

xiamenese
Posts: 422
Joined: 2006-12-08 00:46:44
Location: London or Exeter, UK

Re: Setting The Style For Unstyled Paragraphs

Post by xiamenese » 2009-12-20 07:18:50

Hi Simon, I don't know if this is what fits your case, but if I have an imported file in which I'm going to have to style everything, what I do is immediately select all and apply my body style. Only after that do I go down changing the headings and subheadings and anything else that needs it to what I want.

Too late for this time, I guess, and maybe Kino's macro would suit you better, but that has always been my approach.

Mark

Groucho
Posts: 496
Joined: 2007-03-03 09:55:06
Location: Europe

Re: Setting The Style For Unstyled Paragraphs

Post by Groucho » 2009-12-21 06:25:54

Simon said:
...It came across pretty well but since it was a Pages document that I exported to RTF and then opened it lost all of the styles that I had defined...
Hi, Simon. Have you tried exporting the file into .doc from Pages and opening it in NWPro? I seldom use Pages, yet it seems to me it is peculiar at dropping styles while preserving formatting.

Cheers, Henry.

Post Reply