Adobe 0046100128056 - InDesign - Mac Manual page 84

Javascript
Table of Contents

Advertisement

C
6: Text and Type
HAPTER
var myDocument = app.documents.item(0);
var myPage = myDocument.pages.item(0);
var myTextFrameA = myPage.textFrames.item(3);
var myTextFrameB = myPage.textFrames.item(2);
var myTextFrameC = myPage.textFrames.item(1);
var myTextFrameD = myPage.textFrames.item(0);
//Move WordC between the words in TextFrameC.
myTextFrameD.parentStory.paragraphs.item(-1).words.item(0).move(LocationOptions.befor
e, myTextFrameC.parentStory.paragraphs.item(0).words.item(1))
//Move WordB after the word in TextFrameB.
myTextFrameD.parentStory.paragraphs.item(-2).words.item(0).move(LocationOptions.after
, myTextFrameB.parentStory.paragraphs.item(0).words.item(0))
//Move WordA to before the word in TextFrameA.
myTextFrameD.parentStory.paragraphs.item(-3).words.item(0).move(LocationOptions.befor
e, myTextFrameA.parentStory.paragraphs.item(0).words.item(0))
//Note that moving text removes it from its original location.
When you want to transfer formatted text from one document to another, you also can use the
method. Using the
you must make the document visible and select the text you want to copy. Using
much faster and more robust. The following script shows how to move text from one document to another
using
move
"Creating a text frame" on page
//Create the source document.
var mySourceDocument = app.documents.add();
var mySourcePage = mySourceDocument.pages.item(0);
var mySourceTextFrame =
mySourcePage.textFrames.add({geometricBounds:myGetBounds(mySourceDocument,
mySourcePage), contents:"This is the source text.\rThis text is not the source
text."});
var mySoureParagraph = mySourceTextFrame.parentStory.paragraphs.item(0);
mySoureParagraph.pointSize = 24;
//Create the target document.
var myTargetDocument = app.documents.add();
var myTargetPage = myTargetDocument.pages.item(0);
var myTargetTextFrame =
myTargetPage.textFrames.add({geometricBounds:myGetBounds(myTargetDocument,
myTargetDocument.pages.item(0)), contents:"This is the target text. Insert the source
text before this paragraph.\r"});
//Move the text from the source document to the target document.
//This deletes the text from the source document.
mySoureParagraph.move(LocationOptions.AT_BEGINNING,
myTargetTextFrame.insertionPoints.item(0));
//To duplicate (rather than move) the text, use the following:
//mySoureParagraph.duplicate(LocationOptions.AT_BEGINNING,
myTargetTextFrame.insertionPoints.item(0));
When you need to copy and paste text, you can use the
select the text before you copy. Again, you should use copy and paste only as a last resort; other
approaches are faster, less fragile, and do not depend on the document being visible. (We omitted the
myGetBounds
CopyPasteText tutorial script.)
or
move
duplicate
and
. (We omitted the
duplicate
71, " or see the MoveTextBetweenDocuments tutorial script.)
function from this listing; you can find it in
method is better than using copy and paste; to use copy and paste,
function from this listing; you can find it in
myGetBounds
method of the application. You will need to
copy
"Creating a text frame" on page
Understanding Text Objects 84
move
or
move
duplicate
71, " or see the
is

Hide quick links:

Advertisement

Table of Contents
loading

This manual is also suitable for:

Indesign cs5

Table of Contents