Mombu the Computer Design Forum

Go Back   Mombu the Computer Design Forum > Computer_Design > Add Formatted Text
User Name
Password
REGISTER NOW! Mark Forums Read




Reply Bookmark and Share
1 20th November 10:23
chris_van_jones
External User
 
Posts: 1
Default Add Formatted Text



Hello,

I am trying to create a series of scripts to be used in a template that add/insert formatted text at a cursors location. So far, I have created the following script:

app.selection[0].paragraphs[0].insertionPoints[0].contents = 'Voiceover'

This works just fine, but how do I get this text to automatically select a Paragragh style I have defined.

Thanks!
  Reply With Quote


 


2 20th November 10:23
dave_saunders
External User
 
Posts: 1
Default Add Formatted Text



app.selection[0].paragraphs[0].appliedParagraphStyle = myStyle;

where myStyle is a reference to the paragraph style.

Dave
  Reply With Quote
3 20th November 10:23
chris_van_jones
External User
 
Posts: 1
Default Add Formatted Text


Excellent. I now have a follow-up question. How can I add a new line of text? For example, the above script writes "Voiceover" in BigRed paragraph style. Now I want to add a new line under "Voiceover" that says "Line 2" in a different paragraph style. This is what I have come up with:

app.selection[0].paragraphs[0].insertionPoints[0].contents = 'Voiceover'
app.selection[0].paragraphs[0].appliedParagraphStyle = 'BigRed'
app.selection[0].paragraphs[0].insertionPoints[10].contents = 'Line 2'
app.selection[0].paragraphs[0].appliedParagraphStyle = 'BigRed2'

Thanks Again!
  Reply With Quote
4 21st November 08:51
robert tkaczyk
External User
 
Posts: 1
Default Add Formatted Text


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
  Reply With Quote
Reply


Thread Tools
Display Modes


Some other forums that might be of your interest : Adobe, Adobe after effects, Acrobat, Elements, Golive, Illustrator, Indesign, Premier, Adobe mac, General mac, Acrobat, Golive, Illustrator, Indesign


Copyright © 2006 SmartyDevil.com - Dies Mies Jeschet Boenedoesef Douvema Enitemaus -
666