Adding text. Adobe InDesign CS5
Annonce
Annonce
C HAPTER 6: Text and Type Entering and Importing Text 78
Function myGetBounds(myDocument, myPage) myPageWidth = myDocument.DocumentPreferences.PageWidth
myPageHeight = myDocument.DocumentPreferences.PageHeight
If myPage.Side = idPageSideOptions.idLeftHand Then myX2 = myPage.MarginPreferences.Left
myX1 = myPage.MarginPreferences.Right
Else myX1 = myPage.MarginPreferences.Left
myX2 = myPage.MarginPreferences.Right
End If myY1 = myPage.marginPreferences.Top
myX2 = myPageWidth - myX2 myY2 = myPageHeight - myPage.MarginPreferences.Bottom
myGetBounds = Array(myY1, myX1, myY2, myX2)
End Function
Adding text
To add text to a story, use the contents
property of the insertion point at the location where you want to insert the text. The following sample script uses this technique to add text at the end of a story (for the complete script, see AddText): set myDocument = myInDesign.Documents.Item(1)
Set myTextFrame = myDocument.TextFrames.Item(1)
Rem Add text at the end of the text in the text frame.
Rem To do this, we'll use the last insertion point in the story.
Rem (vbCr is a return character, "&" concatenates two strings.) myNewText = "This is a new paragraph of example text." myTextFrame.ParentStory.InsertionPoints.Item(-1).Contents = vbCr & myNewText
Stories and text frames
All text in an InDesign layout is part of a story, and every story can contain one or more text frames.
Creating a text frame creates a story, and stories can contain multiple text frames.
In the preceding script, we added text at the end of the parent story rather than at the end of the text frame. This is because the end of the text frame might not be the end of the story; that depends on the length and formatting of the text. By adding the text to the end of the parent story, we can guarantee that the text is added, regardless of the composition of the text in the text frame.
You always can get a reference to the story using the
ParentTextFrame
property of a text frame. It can be useful to work with the text of a story instead of the text of a text frame; the following script demonstrates the difference. The alerts shows that the text frame does not contain the overset text, but the story does
(for the complete script, see StoryAndTextFrame).
Set myDocument = myInDesign.Documents.Item(1)
Set myPage = myDocument.Pages.Item(1)
Set myTextFrame = myPage.TextFrames.Item(1)
Rem Now add text beyond the end of the text frame.
myTextFrame.InsertionPoints.Item(-1).Contents = vbCr & "This is some overset text" myString = myTextFrame.Contents
MsgBox ("The last paragraph in this alert should be ""This is some overset text"". Is it?" & vbCr & myString) myString = myTextFrame.ParentStory.Contents
MsgBox ("The last paragraph in this alert should be ""This is some overset text"". Is it?" & vbCr & myString)
Download
Annonce