🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: adobe.scripting.indesign
Article #138

Re: Add Formatted Text

#138
From: Robert Tkaczyk
Date: Fri, 03 Apr 2009 00:52
34 lines
2415 bytes
add "\r" at end of your text contents or as a single character

 app.selection[0].paragraphs[0].insertionPoints[-1].contents = 'Voiceover\r'

or

 app.selection[0].paragraphs[0].insertionPoints[-1].contents = '\r'

if you are building new text in new empty Story or at end of current Story - don't use absolute index - .insertionPoints[10] - use .insertionPoints[-1] as reference to last item

 app.selection[0].paragraphs[-1].insertionPoints[-1].contents = '\r'
(you need to add this line if you want to start new paragraph after existing text)

 app.selection[0].paragraphs[-1].appliedParagraphStyle = 'BigRed'
 app.selection[0].paragraphs[-1].insertionPoints[-1].contents = 'Voiceover\r'
 app.selection[0].paragraphs[-1].appliedParagraphStyle = 'BigRed2'
 app.selection[0].paragraphs[-1].insertionPoints[-1].contents = 'Line 2\r'

like you can see - you need to switch order of lines - first you need to set formatting (ParaStyle) - then set new contents - and this is the best order of operations

step 1 - set formatting to LastInsertionPoint
step 2 - set contents of LastInsertionPoint

thanks to this - you don't need to care how long will be your new text ;)


if you want to add new text to empty TextFrame - you can't refer to first paragraph - because there is no paragraphs in empty TextFrame - you need to refer to insertionPoint - and better - to last insertionPoint of parentStory

 app.selection[0].parentStory.insertionPoints[-1]

robin

-- 
www.adobescripts.com
Technical Details
Message-ID: <EAD1E682AA5C59DB103CA026F2D3CC80@in.webcrossing.la2eafNXanI>
Path: arc1-ca.pugleaf.net!g2news1.google.com!news1.google.com!npeer01.iad.highwinds-media.com!news.highwinds-media.com!feed-me.highwinds-media.com!news.glorb.com!news2.glorb.com!newshub.sdsu.edu!webcrossing
References: <59b87b8f.-1@webcrossing.la2eafNXanI> <59b87b8f.1@webcrossing.la2eafNXanI>

Show Full Headers
Complete Article Headers
X-Google-Thread: f939a,15d68b48193a17a0
X-Google-Attributes: gidf939a,domainid0,public,usenet
X-Google-Language: ENGLISH,ASCII-7-bit
From: Robert Tkaczyk <indesignscripts@wp.pl>
Path: arc1-ca.pugleaf.net!g2news1.google.com!news1.google.com!npeer01.iad.highwinds-media.com!news.highwinds-media.com!feed-me.highwinds-media.com!news.glorb.com!news2.glorb.com!newshub.sdsu.edu!webcrossing
Newsgroups: adobe.scripting.indesign
Subject: Re: Add Formatted Text
Message-ID: <EAD1E682AA5C59DB103CA026F2D3CC80@in.webcrossing.la2eafNXanI>
Date: Thu, 2 Apr 2009 17:52:41 -0700
References: <59b87b8f.-1@webcrossing.la2eafNXanI> <59b87b8f.1@webcrossing.la2eafNXanI>
Lines: 46
User-Agent: Thunderbird 2.0.0.21 (Windows/20090302)
X-Antivirus: avast! (VPS 090402-0, 2009-04-02), Outbound message
X-Antivirus-Status: Clean
MIME-Version: 1.0
Content-Type: text/plain; charset="ISO-8859-1"
Content-Transfer-Encoding: 8bit