Importing from Scrivener in style?

Everything related to our flagship word processor.
Post Reply
braver
Posts: 6
Joined: 2008-08-25 20:15:03

Importing from Scrivener in style?

Post by braver » 2008-08-27 19:21:41

Greetings -- I'd like to import RTF from Scrivener into NWP while assigning titles appropriate styles. Since fixing the lists would need macro anyways, like the one Martin posted earlier, I wonder whether I can compose a larger macro for importing from Scrivener. Now in order to apply heading styles, we can recognize Scrivener fonts -- it allows to assign fonts to titles and export names of cards as titles. How does one make a macro picking a line all in a certain font and converting it into a heading?

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

Re: Importing from Scrivener in style?

Post by Kino » 2008-08-28 04:40:06

braver wrote:How does one make a macro picking a line all in a certain font and converting it into a heading?
The simplest way is to use an attribute sensitive find. Something like

Code: Select all

Find All '^.+', 'Eu'
You have to apply "Format:Remove Attributes and Styles" and the font on '^.+'. Then, you can apply a paragraph style, for example "Heading 1", by

Code: Select all

Menu ':Format:Paragraph Style:Heading 1'
Just a style name will work if there is no command name conflict.

The macro below is a bit complicated but perhaps easy to customize. It assumes that your imported document has lines in Baskerville and Helvetica on which you want to apply paragraph styles "Heading 1" and "Heading 2" respectively. You have to import or create those styles before running the macro.

Code: Select all

 Require Application Version '3.1'
$doc = Document.active
$text = $doc.text
$Baskerville = $Helvetica = Array.new

$index = 0
$limit = $text.length
while $index < $limit
	$attr = $text.displayAttributesAtIndex $index
	$range = $text.rangeOfAttributesAtIndex $index
	if $attr.fontFamilyName == 'Baskerville'
		$sel = TextSelection.new $text, $range
		$Baskerville.appendValue $sel
	end
	if $attr.fontFamilyName == 'Helvetica'
		$sel = TextSelection.new $text, $range
		$Helvetica.appendValue $sel
	end
	$index = $range.bound
end

if $Baskerville.count
	$doc.setSelections $Baskerville
	Menu ':Format:Paragraph Style:Heading 1'
end

if $Helvetica.count
	$doc.setSelections $Helvetica
	Menu ':Format:Paragraph Style:Heading 2'
end

braver
Posts: 6
Joined: 2008-08-25 20:15:03

Re: Importing from Scrivener in style?

Post by braver » 2008-08-29 09:37:59

Kino -- very informative and instructive, thanks a lot! Now I have something to tweak!

User avatar
Icemancometh
Posts: 4
Joined: 2010-09-06 17:28:12
Location: East Coast
Contact:

Re: Importing from Scrivener in style?

Post by Icemancometh » 2010-09-06 18:14:32

My biggest problem (such as it is) importing from Scrivener concerns margins. All imported documents (chapters) have an artificially truncated righthand margin. This is easy to fix, but must be done for each individual chapter in a book, and I suspect the glitch, such as it is, is with Scrivener, as the same document opened in the abominable MS Word has a righthand margin that exceeds the set margin.

g

Post Reply