Page 1 of 1
Setting The Style For Unstyled Paragraphs
Posted: 2007-08-17 14:46:56
by WolfUK
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?
Posted: 2007-08-17 18:27:32
by martin
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?
Posted: 2007-08-17 23:40:53
by WolfUK
Yes, exactly right, I was to select all paragraphs without a paragraph style and apply my Body style.
Posted: 2007-08-19 19:48:30
by martin
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?
Posted: 2007-08-19 23:51:06
by WolfUK
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 ...

Re: Setting The Style For Unstyled Paragraphs
Posted: 2009-12-20 05:29:53
by Kino
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
Re: Setting The Style For Unstyled Paragraphs
Posted: 2009-12-20 07:18:50
by xiamenese
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
Re: Setting The Style For Unstyled Paragraphs
Posted: 2009-12-21 06:25:54
by Groucho
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.