Importing from Scrivener in style?
Importing from Scrivener in style?
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?
Re: Importing from Scrivener in style?
The simplest way is to use an attribute sensitive find. Something likebraver wrote:How does one make a macro picking a line all in a certain font and converting it into a heading?
Code: Select all
Find All '^.+', 'Eu'
Code: Select all
Menu ':Format:Paragraph Style:Heading 1'
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
Re: Importing from Scrivener in style?
Kino -- very informative and instructive, thanks a lot! Now I have something to tweak!
- Icemancometh
- Posts: 4
- Joined: 2010-09-06 17:28:12
- Location: East Coast
- Contact:
Re: Importing from Scrivener in style?
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
g