12.01.2013 Views

Adobe InDesign CS5 Scripting Tutorial

Adobe InDesign CS5 Scripting Tutorial

Adobe InDesign CS5 Scripting Tutorial

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

<strong>Adobe</strong> <strong>InDesign</strong> <strong>CS5</strong> <strong>Scripting</strong> <strong>Tutorial</strong> Adding features to “Hello World” 28<br />

Either open the ImprovedHelloWorld.vbs tutorial script, or perform the following steps to create the<br />

script:<br />

1. Start any text editor (for example, Notepad).<br />

2. Enter the following code:<br />

Set my<strong>InDesign</strong> = CreateObject("<strong>InDesign</strong>.Application")<br />

Rem Enter the name of a font on your system, if necessary.<br />

Set myFont = my<strong>InDesign</strong>.Fonts.Item("Arial")<br />

Set myDocument = my<strong>InDesign</strong>.ActiveDocument<br />

Set myPage = myDocument.Pages.Item(1)<br />

Rem Get page width and page height using the function "myGetBounds".<br />

myBounds = myGetBounds(myDocument, myPage)<br />

Set myTextFrame = myPage.TextFrames.Item(1)<br />

Rem Resize the text frame to match the publication margins.<br />

myTextFrame.GeometricBounds = myBounds<br />

Set myParagraph = myTextFrame.Paragraphs.Item(1)<br />

Rem Change the font, size, and alignment.<br />

If TypeName(myFont) "Nothing" Then<br />

myParagraph.AppliedFont = myFont<br />

End If<br />

myParagraph.PointSize = 48<br />

myParagraph.Justification = idJustification.idCenterAlign<br />

Rem myGetBounds is a function that returns the bounds<br />

Rem of the "live area" of a page.<br />

Function myGetBounds(myDocument, myPage)<br />

myPageWidth = myDocument.DocumentPreferences.PageWidth<br />

myPageHeight = myDocument.DocumentPreferences.PageHeight<br />

If myPage.Side = idPageSideOptions.idLeftHand Then<br />

myX2 = myPage.MarginPreferences.Left<br />

myX1 = myPage.MarginPreferences.Right<br />

Else<br />

myX1 = myPage.MarginPreferences.Left<br />

myX2 = myPage.MarginPreferences.Right<br />

End If<br />

myY1 = myPage.marginPreferences.Top<br />

myX2 = myPageWidth - myX2<br />

myY2 = myPageHeight - myPage.MarginPreferences.Bottom<br />

myGetBounds = Array(myY1, myX1, myY2, myX2)<br />

End Function<br />

3. Save the text as a plain text file with the file extension .vbs in the Scripts folder (see “Installing scripts”<br />

on page 6).<br />

Once you’ve opened or created the script file, you can run the script from the <strong>InDesign</strong> Scripts panel.

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!