Adobe 27510753 Scripting Guide - Page 32
JavaScript, Start InDesign.
UPC - 718659445294
View all Adobe 27510753 manuals
Add to My Manuals
Save this manual to your list of manuals |
Page 32 highlights
24 Getting Started with InDesign Scripting Adobe InDesign CS2 Scripting Guide 2. Use the CommandButton tool to create a new button on the default form. Double-click the button to open the Code window. 3. Enter the following code (between the Private Sub and End Sub lines defining the code under the button). The lines preceded by Rem are comments and are ignored by the scripting system. They're included to describe the operation of the program. As you look through the script, you'll see how we create, then address, each object in turn. You do not need to enter the comments. Rem Hello World Rem Declare variable types (optional if Option Explicit is off). Dim myInDesign As InDesign.Application Dim myDocument As InDesign.Document Dim myPage As InDesign.Page Dim myTextFrame As InDesign.TextFrame Rem End of variable type declarations. Set myInDesign = CreateObject("InDesign.Application.CS2") Rem Create a new document. Set myDocument = myInDesign.Documents.Add Rem Get a reference to the first page. Set myPage = myDocument.Pages.Item(1) Rem Create a text frame. Set myTextFrame = myDocument.TextFrames.Add Rem Specify the size and shape of the text frame. myTextFrame.GeometricBounds = Array("0p0", "0p0", "18p0", "18p0") Rem Enter text in the text frame. myTextFrame.Contents = "Hello World!" 4. Save the form. 5. Start InDesign. 6. Return to Visual Basic and run the program. 7. Click the button you created earlier. InDesign creates a new publication, creates a new text frame, and then enters the text. JavaScript To create a JavaScript: 1. Using any text editor (including InDesign or the ExtendScript Tookit), enter the following text: //Hello World! var myDocument = app.documents.add(); with(myDocument){ var myPage = myDocument.pages.item(0); with(myPage){ //Create a new text frame and assign it to the variable "myTextFrame" var myTextFrame = textFrames.add(); //Specify the size and shape of the text frame. myTextFrame.geometricBounds = [ "0p0", "0p0", "18p0", "18p0"]; //Enter text in the text frame. myTextFrame.contents = "Hello World!" } } 2. Save the text as a plain text file with the file extension .jsx in the Scripts folder inside the Presets folder in your InDesign folder. 3. Test the script by double-clicking the script name in the InDesign Scripts palette.