Text and Type. Adobe CS5 InDesign
Реклама
Реклама
6
Text and Type
Entering, editing, and formatting text are the tasks that make up the bulk of the time spent working on most InDesign documents. Because of this, automating text and type operations can result in large productivity gains.
This chapter shows how to script the most common operations involving text and type. The sample scripts in this chapter are presented in order of complexity, starting with very simple scripts and building toward more complex operations.
We assume that you have already read Adobe InDesign CS5 Scripting Tutorial and know how to create, install, and run a script. We also assume that you have some knowledge of working with text in InDesign and understand basic typesetting terms.
Entering and Importing Text
This section covers the process of getting text into your InDesign documents. Just as you can type text into text frames and place text files using the InDesign user interface, you can create text frames, insert text into a story, or place text files on pages using scripting.
Creating a text frame
The following script creates a text frame, sets the bounds (size) of the frame, then enters text in the frame
(for the complete script, see the MakeTextFrame tutorial script):
--Given a document "myDocument"...
set myDocument to document 1 set myPage to page 1 of myDocument tell myPage set myTextFrame to make text frame
--Set the bounds of the text frame.
set geometric bounds of myTextFrame to {72, 72, 288, 288}
--Enter text in the text frame.
set contents of myTextFrame to "This is some example text."
--Note that you could also use a properties record
--to set the bounds and contents of the text in a
--single line:
--set myTextFrame to make text frame with properties{geometric bounds:{72, 72, 288,
288}, contents:"This is some example text."} end tell
The following script shows how to create a text frame that is the size of the area defined by the page margins. myGetBounds
is a useful function that you can add to your own scripts, and it appears in many other examples in this chapter. (For the complete script, see MakeTextFrameWithinMargins.)
--Given a document "myDocument" set myPage to page 1 of myDocument tell myPage set myTextFrame to make text frame
--Set the bounds of the text frame.
set geometric bounds of myTextFrame to my myGetBounds(myDocument, myPage) end tell
78
Изтегляне
Реклама