Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống
1
/ 30 trang
THÔNG TIN TÀI LIỆU
Thông tin cơ bản
Định dạng
Số trang
30
Dung lượng
673,22 KB
Nội dung
e following script fragment shows the heart of our NINA drawing script—for the complete script, go to David’s web site (see “Where to Get the Scripts in this Chapter,” earlier in this chapter). function myDrawNina(myNumberOfLines, a_pulse, b_pulse, myLength, myClosedPath){ var cur_x, cur_y; var myAnchor = new Array(2); var myArray = new Array; //Rather than draw the entire path point-by-point, //we'll fill an array and then use it to fill in all of the point //locations at once using the entirePath property. for (var myCounter = 0; myCounter < myNumberOfLines; myCounter++){ cur_x = (Math.cos((-2 * Math.PI * a_pulse * myCounter) / myNumberOfLines) + Math.cos((-2 * Math.PI * b_pulse * myCounter) / myNumberOfLines)) * myLength; cur_y = (Math.sin((-2 * Math.PI * a_pulse * myCounter) / myNumberOfLines) + Math.sin((-2 * Math.PI * b_pulse * myCounter) / myNumberOfLines)) * myLength; myAnchor = [cur_x, cur_y]; myArray.push(myAnchor); } app.activeDocument.viewPreferences.horizontalMeasurementUnits = MeasurementUnits.points; app.activeDocument.viewPreferences.verticalMeasurementUnits = MeasurementUnits.points; var myPage = app.activeWindow.activePage; var myGraphicLine = myPage.graphicLines.add(); myGraphicLine.move(undefined, ["1p","1p"]); var myPath = myGraphicLine.paths.item(0); //Now set the entire path to the contents of the array. myPath.entirePath = myArray; if(myClosedPath == true){ myPath.pathType = PathType.closedPath; } else{ myPath.pathType = PathType.openPath; } //Label the graphic line with the parameters used to create it. myGraphicLine.label = "number_of_lines = " + myNumberOfLines + ", a_pulse = " + a_pulse + ", b_pulse = " + b_pulse; } e following script fragment shows the heart of our NINA drawing script—for the complete script, go to David’s web site (see “Where to Get the Scripts in this Chapter,” earlier in this chapter). As usual, “_” indicates a line break in this layout; do not break the line or type the character). Function myDrawNina(myInDesign, myNumberOfLines, a_pulse, b_pulse, _ myLength, myClosedPath) pi = 3.14159265358979 Set myDocument = myInDesign.ActiveDocument JavaScript Visual Basic Real_World_Adobe_InDesign_CS4b.pdf 721Real_World_Adobe_InDesign_CS4b.pdf 721 08/04/2009 05:56:09 p.m.08/04/2009 05:56:09 p.m. . Set myPage = myInDesign.ActiveWindow.ActivePage ReDim myArray(myNumberOfLines) Rem Fill in an array with point locations. For myCounter = 0 To (myNumberOfLines) cur_x = (Cos((-2 * pi * a_pulse * myCounter) / myNumberOfLines) _ + Cos((-2 * pi * b_pulse * myCounter) / myNumberOfLines)) * _ myLength cur_y = (Sin((-2 * pi * a_pulse * myCounter) / myNumberOfLines) _ + Sin((-2 * pi * b_pulse * myCounter) / myNumberOfLines)) * _ myLength myArray(myCounter) = Array(cur_x, cur_y) Next Set myGraphicLine = myPage.GraphicLines.Add Rem Move the graphic line a bit to clear up Rem page "ownership" issues. myGraphicLine.Move , Array("1p", "1p") Rem Set the points on the path to the array generated by the loop. myGraphicLine.Paths.Item(1).EntirePath = myArray Rem Label the NINA with settings. myGraphicLine.Label = "number_of_lines = " & CStr(myNumberOfLines)_ & ", a_pulse = " & CStr(a_pulse) & ", b_pulse = " & CStr(b_pulse) If myClosedPath = True Then myGraphicLine.Paths.Item(1).PathType = idPathType.idClosedPath Else myGraphicLine.Paths.Item(1).PathType = idPathType.idOpenPath End If End Function To test the NINA drawing script, move InDesign’s ruler zero point to the point at which you want to locate the center of the shape, then run the script (we recommend setting the publication’s measurement system to points before running the script). If all goes well, InDesign will draw a NINA. We urge you to experiment with the settings in the script—the number of dierent types of shapes you can draw is truly endless. Even very slight changes to the settings can produce wildly diering results. InDesign scripts can create their own dialog boxes, and can populate those dialog boxes with static text labels, check box controls, pop-up menus, text entry elds, and a variety of number entry elds (mea- surement units, integers, percentages, and real numbers). Previously, adding a user interface to a script meant you had to rely on addi- tional user interface building soware, such as FaceSpan, Real Basic, or AppleScript Studio on the Mac OS, or the full version of Visual Basic in Windows. Having to rely on these add-on products made your scripts larger, and complicated sharing scripts with others. ere’s good news and bad news about InDesign script dialog boxes. e good news is that InDesign takes care of all spacing and sizing issues. e bad news? InDesign takes care of all spacing and Testing the NINA Drawing Script Adding a User Interface Real_World_Adobe_InDesign_CS4b.pdf 722Real_World_Adobe_InDesign_CS4b.pdf 722 08/04/2009 05:56:09 p.m.08/04/2009 05:56:09 p.m. sizing issues. is means that you don’t have to worry about setting pixel coordinates for every control, but it also means that you have very little control over the appearance of your dialog boxes. At the same time, it’s relatively easy to create a good-looking dialog box. e NINA drawing script a good one to add a user interface to—all you need is a dialog box containing four text elds (to set the myNumberOf Lines, a_pulse, b_pulse, and myLength variables) and OK/Cancel buttons. We’ve provided a version of the NINA drawing script with a user interface—you can download it from David’s web site (see “Where to Get the Scripts in this Chapter,” earlier in this chapter). When you run the script, InDesign will display a dialog box (see Figure 12-8). Use the version with the user interface, and you won’t have to edit the script to draw dierent NINAs. Mystic Rose Another interesting geometric gure is the “Mystic Rose”—a poly- gon where every point connects to every other point. Ole thought it would be fun to have a script that would draw these, so he wrote one (see Figure 12-9). We’ve included this script with the other scripts in the Zip archive you can download from David’s web site (see “Where to Get the Scripts in this Chapter,” earlier in this chapter). Monitoring Events “Events” are things that happen in InDesign. Opening a le, printing a le, importing a graphic, and moving an object are all examples of events. InDesign can watch for a certain set of events, and can run scripts when those events occur. e set of events that InDesign can respond to is, at present, rather limited. You can monitor the follow- ing events (the event names are shown in parentheses). Opening a document (beforeOpen, aerOpen) Creating a new document (beforeNew, aerNew) Saving a document (beforeSave, aerSave, beforeSaveACopy, aerSaveACopy, beforeSaveAs, aerSaveAs) Closing a document (beforeClose, aerClose) Exporting (beforeExport, aerExport) Real_World_Adobe_InDesign_CS4b.pdf 723Real_World_Adobe_InDesign_CS4b.pdf 723 08/04/2009 05:56:09 p.m.08/04/2009 05:56:09 p.m. . Displaying a menu (beforeDisplay, aerDisplay, beforeInvoke, aerInvoke, onInvoke) Printing a document (beforePrint, aerPrint) Placing a le (beforeImport, aerImport) Reverting a document (beforeRevert, aerRevert) While this list is limited, there are a number of great places here to have scripts run automatically. You can use the beforePrint event, for example, to trigger a custom preight script. A script attached to the aerNew event add XMP metadata (“le info”) to the document. One important thing to note about event scripting: JavaScripts can process the events using functions inside the event handling script, but AppleScript and VBScript event scripts must call external scripts. at’s why the AppleScript and VBScript sample script fold- ers include a folder containing three additional scripts (relative to the JavaScript version)—they make the LabelGraphicMenu script work. Take a look at the “Events” chapter in the AdobeInDesign CS4 Scripting Guide for more on attaching scripts to events. InDesign dialog boxes can include a range of controls not shown in this example, including pop-up menus, check boxes, and a variety of other number and text entry elds (only measurement edit box controls and integer edit box controls are shown here). As in all other InDesign numeric entry elds, you can do arithmetic and enter measurement overrides in these elds. - NINA User Interface By adding a user interface to your script, you can make it much easier to use. is example dialog box was gen- erated by InDesign—no Dia- logDirector, no AppleScript Studio, no Visual Basic form. How cool is that? - Mystic Rose Real_World_Adobe_InDesign_CS4b.pdf 724Real_World_Adobe_InDesign_CS4b.pdf 724 08/04/2009 05:56:09 p.m.08/04/2009 05:56:09 p.m. Menu Scripting InDesign scripting can run any menu item, and can associate scripts with new menu items. anks to the events mentioned in the pre- vious section, scripts associated with menu items (most notably the Context menus) can check the selection to see whether they should display themselves or not. A script can check to see that a graphic is selected, for example, before it displays a menu items for working with a graphic. Because the process of attaching a script to a menu item is fairly complicated, we’re not going to show an example here. We thought, however, that we’d mention it as something you should keep in mind. If you’re curious about what it takes to add a script to a menu item, take a look at the “Menus” chapter in the AdobeInDesign CS4 Script- ing Guide for your preferred scripting language. Startup Scripts If you have a script you really like, and want to have the script run whenever you start InDesign, you can. ere’s no real trick to it: just put the script inside a folder named “Startup Scripts” anywhere in the Scripts folder in your InDesign folder. When you do this, the script will run whenever you launch InDesign. At the same time, some scripts will need modication to be run as startup scripts. Take, for example, the very useful sample script LabelGraphicMenu that comes with InDesign. is script installs a new menu item on the Context menu when you have a graphic selected. Choose the menu item, and you can easily add a caption to the graphic (see Figure 12-18). e only trouble with this script is that it asks (politely) if it can do what it does whenever you run it. You don’t want to have to respond to this question every time you start InDesign, so you’d better make a change to the script before you put it in the Startup Scripts folder. If you’re using AppleScript or VBScript, you’ll also have to move a folder containing three “helper” scripts to the same folder as the script itself. To convert the sample script LabelGraphicsMenu.applescript to a startup script, follow these steps. 1. Open the script with your script editor. 2. Locate the line: AppleScript Real_World_Adobe_InDesign_CS4b.pdf 725Real_World_Adobe_InDesign_CS4b.pdf 725 08/04/2009 05:56:10 p.m.08/04/2009 05:56:10 p.m. . set myResult to display dialog myString buttons{"Yes", "No", default button: "Yes"} 3. Enter “ ” before the start of the line to make it a comment. 4. Locate the line: if button returned of myResult is "Yes" then And change it to: if true then 5. Save the script. 6. Put the edited version of the script and the LabelGraphic Support folder inside a folder named “Startup Scripts” in the Scripts folder inside your InDesign folder. Create the folder if it does not already exist. To convert the sample script LabelGraphicMenu.jsx to a startup script, follow these steps. 1. Open the script with the ExtendScript Toolkit. 2. Locate the line: var myResult = confirm("This script installs a new menu item 'Label Graphic' \ron the context menu that appears when you select one or more graphics.\r\rClick the Yes button to add the menu item."); And change it to: var myResult = true; 3. Save the script. 4. Put the edited version of the script inside a folder named “Startup Scripts” in the Scripts folder inside your InDesign folder. Create the folder if it does not already exist. To convert the sample script LabelGraphicMenu.vbs to a startup script, follow these steps. 1. Open the script with your script editor. 2. Locate the line: myResult = MsgBox(myString, vbOKCancel, "Install Label Graphic menu item?") JavaScript VBScript Real_World_Adobe_InDesign_CS4b.pdf 726Real_World_Adobe_InDesign_CS4b.pdf 726 08/04/2009 05:56:10 p.m.08/04/2009 05:56:10 p.m. And change it to: myResult = vbOK 3. Save the script. 4. Put the edited version of the script and the LabelGraphic Support folder inside a folder named “Startup Scripts” in the Scripts folder inside your InDesign folder. Create the folder if it does not already exist. End Script Scripting is all about empowerment. Don’t just sit around telling yourself that the reason you’re working late is that InDesign can’t do something you’d like it to do. Sure, there are things in every program we’d like the manufacturer to x, but, with InDesign’s scripting fea- tures, we’ve nally got the tools we need to x them ourselves. By urging you to take up scripting, we’re urging you to take con- trol of InDesign, your publications, your work, and your life. We know you can do it! Real_World_Adobe_InDesign_CS4b.pdf 727Real_World_Adobe_InDesign_CS4b.pdf 727 08/04/2009 05:56:10 p.m.08/04/2009 05:56:10 p.m. A hundred years ago, when David was a young pup, he turned in a school essay he had typed using an amazing new device called a per- sonal computer and printed on that technological marvel, the dot- matrix printer. His teacher was so impressed that she wrote her copi- ous corrections on a separate page, so as not to spoil the appearance of David’s “professionally published” work. Today, a school report printed on a color laser or inkjet printer is de rigueur, and teachers may question a student’s work ethic if they don’t have a correspond- ing Web site and public relations team. Communication of data has come a long way, and while print is far from dead, you can bet that the future of publishing isn’t solely a matter of throwing more ink at paper. Today’s communicators have to be adept at creating both print and interactive documents—les that include buttons, sounds, and movies. Fortunately, InDesign oers a number of features for the “rich media” producer. Many of these tools don’t produce any visible eect on your InDesign pages, but change the behavior of PDF or Flash SWF les that you export. Interactive Documents 13 Real_World_Adobe_InDesign_CS4b.pdf 728Real_World_Adobe_InDesign_CS4b.pdf 728 08/04/2009 05:56:10 p.m.08/04/2009 05:56:10 p.m. Interactive Only Aer Export e key thing to understand about InDesign’s interactive features is that they only work when you export the le to a format that can support them, such as PDF, SWF, or XHTML. And, dierent formats support dierent features. Acrobat PDF. You may not expect that the PDF format has the most wide range of support for interactive media—at least in terms of what you can export from InDesign. However, you should plan on using the Acrobat 6 format (or later). e earlier Acrobat 4 or 5 (that’s PDF version 1.3 and 1.4) formats don’t support some le formats, embed- ding movies in the PDF, CMYK or non-rectangular posters (more on what posters are later in this chapter), or support for interactive objects on the same page as transparency eects (such as feathering and opacity). That said, even Acrobat 6, 7, and 8 les don’t support all the rich- media tools you might want. For example, there are still a limited number of page turn transitions, and MP3 sound les don’t work. Also note that you should use Acrobat Reader or Acrobat Pro to view interactive PDF les—while other PDF readers (such as Preview in Mac OS X) can open them, most of the media features won’t work. Unfortunately, although you can import most avors of SWF into InDesign (we’ll explain how later in this chapter), when you export a PDF le, Acrobat has signicant problems displaying the SWF—even Acrobat 9, which has the Flash Player built in! erefore, if you want to add SWF les to your interactive PDF les, we suggest adding them manually in Acrobat Pro, aer you have exported the PDF from InDesign. We hope that this will be xed before too long. We cover how to export PDF les in Chapter 7, “Importing and Exporting.” XHTML and ePub. InDesign has very limited support for XHTML and ePub documents. However, hyperlinks that you create in InDesign are exported properly. We cover how to export XHTML and .epub documents from InDesign in Chapter 7, “Importing and Exporting.” SWF. InDesign can export one or more pages from your document directly to the SWF (Shockwave Flash) format. We’ll discuss this in more detail later in this chapter, but it’s important to note that only buttons, hyperlinks, and page transitions are honored in your nal SWF le—imported sounds and movies are stripped out. And, in fact, buttons that interact with transparency eects, and some button actions themselves (such as Go to Next View) are also not honored. Real_World_Adobe_InDesign_CS4b.pdf 729Real_World_Adobe_InDesign_CS4b.pdf 729 08/04/2009 05:56:10 p.m.08/04/2009 05:56:10 p.m. . XFL. InDesign’s SWF export is cool for simple projects, but limited to a few simple eects. If you know ActionScript, or you’re working with a Flash developer, you’re going to want to export your InDesign document in the XFL format, which is an interchange format that Flash CS4 Professional can read. But again, there are caveats: the XFL format strips out all the interactivity you’ve added in InDesign—so if you’re heading for XFL, you might as well skip making hyperlinks, buttons, movies, and page transitions. Hyperlinks What is an interactive page without links? Links help your readers explore your le, jumping between pages, to other documents, or even to Web sites. You can also add links to les that your readers can download, and you can add links for sending email. PDF les oer three kinds of links: hyperlinks, bookmarks, and buttons. Let’s look at each of these in turn. A hyperlink is essentially a button—it’s a “hot” area that performs some action when you click it. ere are two big dierences between a hyperlink and a button: First, you can apply a hyperlink directly to a range of text—though behind the scenes, InDesign is still more or less drawing a button around that text. Second, you can save a hyper- link destination and use it more than once. To make a hyperlink, you’ll need to open the Hyperlinks panel from the Interactive submenu under the Window menu. e Hyper- links panel also includes the Cross-References panel; we discuss cross-references in Chapter 3, “Text.” Named versus Unnamed Hyperlinks When you make a hyperlink, you need to decide whether it should be a hyperlink that can be used multiple times (which InDesign calls a “Shared Hyperlink Destination”), or a one-o link. Because these are similar in concept to named and unnamed color swatches, we tend to call these named and unnamed hyperlinks. Named hyperlinks are actually easier to make, but they can slow you down if you’re going to make dozens (or hundreds) of them, because each one you add takes a position on the Hyperlink panel’s URL pop-up menu. Searching through 100 URLs is a hassle. ere- fore, although we tend to eschew unnamed color swatches, we actu- ally use unnamed hyperlinks most of the time. On the other hand, if you are going to use a hyperlink several times in a document, it’s great to make it named. at way, if you Real_World_Adobe_InDesign_CS4b.pdf 730Real_World_Adobe_InDesign_CS4b.pdf 730 08/04/2009 05:56:10 p.m.08/04/2009 05:56:10 p.m. [...]... choose Default Poster from the Poster pop-up menu, InDesign grabs the default poster image from the movie (which is almost always the first frame of the movie) If you prefer to use a different frame from the movie, select Real_ World_ Adobe_ InDesign_ CS4b.pdf 746 08/04/2009 05:56:13 p.m 734 realworldadobeindesign cs4 Choose Movie Frame as Poster; InDesign lets you scroll through the movie until you... Export PDF dialog box, or the Include Buttons checkbox in the Export SWF dialog box Real_ World_ Adobe_ InDesign_ CS4b.pdf 738 08/04/2009 05:56:11 p.m 726 realworldadobeindesign cs4 The Way of Buttons It’s important to remember that buttons are containers, like a special kind of frame When you turn an object into a button, InDesign actually puts that object inside a button “frame.” This means you can select... you’ll need to update your hyperlink source To do that, select the hyperlink source in the Hyperlinks panel and choose Update Hyperlink from the panel menu If the Real_ World_ Adobe_ InDesign_ CS4b.pdf 736 08/04/2009 05:56:11 p.m 724 realworldadobeindesign cs4 other document isn’t currently open, you’ll need to hold down the Option/Alt key when choosing Update Hyperlink Exporting Hyperlinks As we noted... have selected Double-click the hyperlink to display the Edit Hyperlink dialog box When you change the Link To pop-up menu, you get a different set of options Real_ World_ Adobe_ InDesign_ CS4b.pdf 732 08/04/2009 05:56:10 p.m 720 realworldadobeindesign cs4 ▶ Email If you want your link to send you an email, you could make a URL link that begins with mailto://, but it’s easier to set the Link To pop-up... Like a URL hyperlink, the Go to URL action hands off the URL you specify to the default Web browser This can be any URL, including http://, file://, or mailto: Real_ World_ Adobe_ InDesign_ CS4b.pdf 740 08/04/2009 05:56:12 p.m 728 realworld adobe indesign cs4 ▶ Movie If you have placed a movie or animation file (see “Audio and Video,” later), you can control it using the Movie action After selecting Movie,... inside the button) and rotating it Basically, each state actually contains a different object and the Buttons panel gives you a way to make each one visible—one Real_ World_ Adobe_ InDesign_ CS4b.pdf 742 08/04/2009 05:56:12 p.m 730 realworld adobe indesign cs4 Figure 13-5 Creating Rollovers To create rollovers, you save multiple versions of a button using the Buttons panel It’s something like a library... later when you create the hyperlink ▶ Text Anchor The Text Anchor option lets you create an anchor to a specific piece of text in your document Once you have Real_ World_ Adobe_ InDesign_ CS4b.pdf 734 08/04/2009 05:56:11 p.m 722 realworld adobe indesign cs4 Figure 13-2 Creating a New Hyperlink Destination Select New Hyperlink Destination Use the Type pop-up menu to select the type of hyperlink destination... the same thing, but the latter displays a dialog box that shows you all the transitions at the same time In either case, you can get a preview of the transition Real_ World_ Adobe_ InDesign_ CS4b.pdf 748 08/04/2009 05:56:13 p.m 736 realworld adobe indesign cs4 Figure 13-8 Page Transitions panel Tired of transitions? You can clear your document of them by choosing Clear All from the panel menu by placing... 05:56:13 p.m 732 realworld adobe indesign cs4 Figure 13-6 Placing a Movie Movie placed on an InDesign page In some cases, InDesign generates a poster (preview) image for the movie, though it didn’t in this example Choose Place from the File menu, select a movie file, and then click the Open button to import the movie To set options for the movie, double-click the movie with the Selection tool InDesign displays... diagrams and explanations were competently done.) Real_ World_ Adobe_ InDesign_ CS4b.pdf 743 08/04/2009 05:56:12 p.m chapter 13 interactive pdf 731 You can add a wide variety of audiovisual files to your files— InDesign supports WAV, AIF, and AU sound file formats, and QuickTime, AVI, MPEG, and SWF movie formats As Acrobat evolves to support more formats, we’re sure InDesign will follow suit As we said earlier, . gen- erated by InDesign no Dia- logDirector, no AppleScript Studio, no Visual Basic form. How cool is that? - Mystic Rose Real_ World_ Adobe_ InDesign_ CS4b.pdf 72 4Real_ World_ Adobe_ InDesign_ CS4b.pdf. urging you to take con- trol of InDesign, your publications, your work, and your life. We know you can do it! Real_ World_ Adobe_ InDesign_ CS4b.pdf 72 7Real_ World_ Adobe_ InDesign_ CS4b.pdf 727 08/04/2009. also not honored. Real_ World_ Adobe_ InDesign_ CS4b.pdf 72 9Real_ World_ Adobe_ InDesign_ CS4b.pdf 729 08/04/2009 05:56:10 p.m.08/04/2009 05:56:10 p.m. . XFL. InDesign s SWF