1. Trang chủ
  2. » Công Nghệ Thông Tin

Tài liệu InDesign CS5 Bible- P18 pptx

50 309 0
Tài liệu đã được kiểm tra trùng lặp

Đang tải... (xem toàn văn)

Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống

THÔNG TIN TÀI LIỆU

Thông tin cơ bản

Tiêu đề Working with xml
Thể loại tài liệu
Định dạng
Số trang 50
Dung lượng 769,61 KB

Các công cụ chuyển đổi và chỉnh sửa cho tài liệu này

Nội dung

In this dialog box, give the XML file a name in the Save As field InDesign automatically adds the file name extension .xml, select a folder in which to place the file, and — most importa

Trang 1

Exporting XML Files

When the InDesign document has the proper elements properly tagged to the document’s content, you’re ready to export it to an XML file for use by a Web site’s content management system or other XML database Choose File ➪ Export or press Ô+E or Ctrl+E to open the Export dialog box

In this dialog box, give the XML file a name in the Save As field (InDesign automatically adds the file name extension xml), select a folder in which to place the file, and — most important — choose XML from the Format popup menu (on the Mac) or Save as Type popup menu (in Windows) Then click Save

The Export XML dialog box appears It opens with the General pane This pane is simple:

l Include DTD Declaration: Select this check box to include the DTD information in the

exported file Otherwise, the XML database needs to import the DTD file separately

l View XML Using: Select this check box and select a Web browser or Web-supporting

application in the adjacent popup menu to preview the XML file in that browser or program

l Export from Selected Element: If an element is selected in the Structure pane, the

Export from Selected Element check box is available; if it’s selected, it exports the XML file only from that element on

l Export Untagged Tables as CALS XML: To convert InDesign tables not tagged with

XML attributes to the CALS XML format, select this check box

l Remap Break, Whitespace, and Special Characters: To convert special characters to

their XML codes, select this check box

l Apply XSLT: If this check box is selected, InDesign applies the XSLT style sheet either

from the XML file or from a separate file; you specify which by using the popup menu to its right

l Encoding: Use this popup menu to choose the text encoding mechanism — a way of

representing international characters across different computer systems Your content engineer or Webmaster will tell you whether to select UTF-8, UTF-16, or Shift-JIS

In the Graphics pane, you tell InDesign how to handle the output of any tagged pictures Your options are as follows:

l Image Options section: Here, you indicate what images to copy to the Images subfolder

that InDesign creates Your choices are Original Images, Optimized Original Images, and Optimized Formatted Images You can select any or all of these The optimized images are converted to GIF or JPEG for use on the Web unless you specify GIF or JPEG in the Image Conversion popup menu rather than leave the default setting of Automatic; the formatted images crop the images to reduce file size

l GIF Options section: Here, you choose the color palette in the Palette popup menu, with

choices of Adaptive (No Dither), Web, System (Mac), and System (Win) Ask your Webmaster what to use; usually, you select Adaptive (No Dither) For very large images,

Trang 2

interlacing can make on-screen display over the Web seem faster (by building the image line by line rather than waiting until the whole image has been transferred to the browser before anything appears); if you want to have such interlaced display of GIF files, select the Interlace option.

l JPEG Options section: Here, you have options similar to those for GIF files In the Image

Quality popup menu, choose the desired image quality (Low, Medium, High, and Maximum) In the Format Method, choose Progressive to have the file displayed progres-sively (similar to the interlace option for GIF files) or Baseline to display it all at one time

Unless your images are very large, keep the default Baseline

When you export an XML file with graphics, InDesign automatically embeds XMP media ment properties with the graphics’ tags You can view those properties by choosing File ➪ File Info

manage-or pressing Option+Shift+Ô+I manage-or Ctrl+Alt+Shift+I and then choosing the Advanced pane This information may be of interest to your content engineer but has no real meaning for the page designer However, the content engineer may want to fill out the information in the File Info dialog box’s other panes — Description and Origin — into which you can add comments, creator infor-mation and contact details, copyright information, credit and source information, keywords, and copyright URLs

Exporting to IDML

Another way to export to XML format is by using the InDesign Markup Language (IDML) format

IDML is based on XML, so developers can work on InDesign layouts without needing InDesign

Note that IDML is not exactly XML, so only IDML-aware programs can use the IDML format; these are typically special apps or plug-ins to XML-aware apps meant to work specifically with InDesign files For example, a company might add IDML capabilities to a catalog publishing system so that it can generate InDesign files directly from its catalog databases

You export an InDesign layout to IDML format by choosing InDesign Markup (IDML) in the Format popup menu (on the Mac) or Save as Type popup menu (in Windows) in the Export dialog box (choose File ➪ Export or press Ô+E or Ctrl+E) There are no options; InDesign just creates the IDML file when you click Save

Trang 3

InDesign lets you tag content within documents with XML tags, so you can transfer that content to

an XML database or Web content engine from which it can be used in a variety of media, ted as appropriate for each You can also import XML content into InDesign, automatically placing content into the appropriate frames if you’ve created an appropriate template and tagged it with the right XML tags But InDesign’s XML tools are only the beginning — you need an XML database and content-creation and content-presentation tools to use the XML data derived from InDesign documents

format-For organizations creating complex content creation and management workflows using XML, InDesign exposes all of its functionality as XML rules that can be scripted, essentially letting you flexibly control the creation of InDesign files based on XML programming and XML data attributes

It also has the new InDesign Markup Language (IDML) file format that is based on XML, so opers can create and work with InDesign-compatible files in their own apps, using XML as the standard description for any elements they work with across apps

Trang 5

devel-Using Scripts

IN THIS CHAPTERInstalling and accessing scripts Exploring JavaScript

Exploring AppleScript Exploring VBA Writing scripts Learning more about scripting

Scripting automates many features in InDesign — it’s essentially a way

to program InDesign to do specific actions Because InDesign uses standard script languages, you can also run scripts that work with multiple programs in concert, including InDesign (All the applications must support the same scripting language, of course.) For example, you might use scripts to automate database publishing, such as to run a database search, export data to a text file, import that file into InDesign, and then apply the appropriate formatting

InDesign supports three scripting languages:

l JavaScript on both Mac and Windows

l AppleScript on the Mac only

l Visual Basic for Applications (VBA) on Windows onlyBecause only JavaScript is supported by both platforms, I recommend you use it wherever possible so that your scripts can work in cross-platform envi-ronments InDesign doesn’t force you to choose just one scripting language,

so you could keep using old AppleScript or VBA scripts created for previous versions of InDesign, as well as new scripts written in JavaScript

As you become comfortable with scriptwriting, you’re also likely to discover that virtually everything you do with InDesign is a repetitive task The more you can free yourself of this kind of work by using scripts, the more time you have to be creative The possibilities are endless But before you get too excited, remember that scripting is programming, so most layout artists stay clear of it, using scripts only if they have a programmer available to write them

Trang 6

Using Scripts

Accessing scripts is easy; they show up in the Scripts panel (choose Window ➪ Utilities ➪ Scripts or press Option+Ô+F11 or Ctrl+Alt+F11) if you’ve placed scripts in the Scripts folder inside the folder that contains the InDesign application, as shown in Figure 37.1 Scripts don’t have to be in the Scripts folder — they can be anywhere on your computer — but to use them outside this folder means you have to double-click them from your desktop rather than have access from within InDesign

When running scripts, keep the following tips in mind:

l You can undo all of a script’s action by using the InDesign Undo command (choose Edit ➪ Undo or press Ô+Z or Ctrl+Z) by ensuring that Undo Affects Entire Script is enabled in the Scripts panel’s flyout menu Otherwise, the undo command reverses just the last action within the script, requiring you to undo several times to roll back the com-plete script action

l By enabling the Enable Redraw flyout menu option in the Scripts panel, you can force InDesign to redraw the display while a script is running This ensures that any changes to the document are immediately visible

New Feature

You can now access InDesign’s Tools panel and its tools via scripts in InDesign CS5 n

Trang 7

Script locations

Whether you create your own scripts or get them from vendors or other users, you need to save them so that InDesign knows they exist You have a choice of two locations:

l The Scripts folder inside the InDesign application folder You can usually find it as

Applications:AdobeInDesignCS5:Scripts in Mac OS X, and ProgramFiles\Adobe\InDesignCS5\Scripts in Windows This makes the script available

to all users of your computer If you want the script to start when InDesign launches, place it in the StartupScripts subfolder

l The ScriptPanel folder This makes the script available only to that specific user

(note that it will appear in a folder called User in your Scripts panel) The path varies based on your operating system:

l On the Mac, the path is Users:username:Library:Preferences:AdobeInDesign:Version7.0:en_US:Scripts:ScriptsPanel

l In Windows XP, the path is DocumentsandSettings\username\ApplicationData\Adobe\InDesign\Version7.0\en_US\Scripts\ScriptsPanel

l In Windows Vista, the path is Users\username\AppData\Roaming\Adobe\

InDesign\Version7.0\en_US\Scripts\ScriptsPanel

l In Windows 7, the path is Users\username\AppData\Roaming\Adobe\

InDesign\Version7.0\en_US\Scripts\ScriptsPanel.The script shows up in the Scripts panel If it doesn’t show up immediately, quit and reopen InDesign

Tip

To use scripts developed for InDesign CS4, create a new folder called Version6.0Scripts inside the

Scripts or ScriptPanel folder and move your old scripts there Likewise, scripts developed for InDesign CS3 should be placed in a folder called Version5.0Scripts These scripts then work in InDesign CS5 n

Scripting principles

No matter what scripting language you use, there are several basic principles to observe These fall into four basic categories:

l Grammar: All languages — including programming languages such as Pascal and C++, as

well as scripting languages — include grammatical components that are used in ized sequences In English, we combine nouns, verbs, adjectives, adverbs, and so on to create sentences Everybody knows the meaning of “The weather is especially nice today,”

standard-because it uses common words in a sequence that makes sense The sentence “Nice is the especially today weather” has the right components but it’s arranged in the wrong sequence, so the meaning is lost

Trang 8

l Statements and syntax rules: In JavaScript, AppleScript, and VBA, verbs, nouns,

adjec-tives, and prepositions are combined to create statements; statements are combined to

form scripts Verbs are also called commands and methods; nouns are called objects; and adjectives are called properties Syntax rules specify how statements and scripts must be

constructed so that a computer can understand them

l Object hierarchy: All three scripting languages use a structural element called an object

hierarchy It’s a fancy term for a simple concept An object hierarchy works like a set of

boxes within boxes A large box contains a smaller box, which contains a smaller box, which contains a smaller box, and so on, until you reach the smallest box, which contains nothing and is the final level in the hierarchy of boxes

l InDesign hierarchy: InDesign contains its own hierarchy, which lends itself nicely to

scripting A document contains pages, pages contain frames, and frames contain text and pictures You can create scripts that perform actions at any of these levels In other words, with scripts you can create documents, add pages, add items to pages, and modify the contents of frames, right down to a particular character in a text frame You can think of this hierarchy in InDesign as a chain of command You can’t talk directly to an item that’s

at the bottom of the chain Rather, you must first address the top level, and then the next, and so on, until you’ve reached the item at the bottom of the chain This is analogous to the way you use InDesign: You create new documents, add pages, place text and graphics

on the pages, and, finally, modify the contents of the frames containing those items

If you’re thinking about dabbling with any of the scripting languages supported by InDesign, the following words of both caution and encouragement are in order First the encouragement: You don’t necessarily need programming experience, scripting experience, or a pocket protector to begin creating scripts A bit of curiosity and a touch of patience will suffice Now the caution:

Scripting is essentially a euphemism for programming (that is, figuring out the right commands and then typing them for the application to execute) Writing scripts isn’t a matter of choosing commands from menus, and clicking and dragging them, or entering values into fields; nor is it like writing a limerick If you’re starting from scratch, know in advance that you have to learn some new skills

Learning to create scripts is like learning to swim: You can read books, documentation, and articles until your head spins, but eventually you have to get a little wet The best way to learn about scripting is to write a script So put on your swimsuit and dive in

Be forewarned: There’s something almost narcotic about creating scripts, and it’s not uncommon for novice scriptwriters to get hooked Don’t be surprised if what starts out to be a 15-minute look-see turns into a multihour, late-night programming episode

Note

Because scripting languages differ, you can’t always duplicate the functionality of a specific script in one guage into a script written in a different language n

Trang 9

There are lots of JavaScript editor programs available Most of these are developed by individuals and small firms, so the list is always changing I recommend you use the Google search engine (www.google.com) and search for JavaScript editor to find the most current programs A great

script-editing program for Mac users is Bare Bones Software’s venerable BBEdit; you can get more information at www.barebones.com

Learning the language

JavaScript is a very complex language based on object-oriented programming, which abstracts items and attributes as objects that are then grouped, changed, or otherwise manipulated This means that JavaScript is less English-like than other scripting languages because it requires you to spend a fair amount of time setting up the objects before you can manipulate them

myObject.strokeTint = newValue;

This example shows that there is a current object named strokeTint being set to a new value;

the actual value for newValue is set earlier in the script

What you need to write and run scripts

You need a program that can display, edit, and test your JavaScript; there is no bundled JavaScript editor in Windows or Mac OS X Such editors typically format the JavaScript code for you, indent-ing it automatically, graying out comments, and highlighting certain keywords

You can use a word processor or text editor to write and edit scripts, but such programs can’t check the syntax or automatically format the script text to help show nested loops, conditional branches, and so on Also, you can usually use an HTML editor such as Adobe Dreamweaver in which to edit JavaScripts, though they also typically don’t provide any debugging tools to help you track and fix coding (syntax) errors (Figure 37.2 shows a JavaScript script being edited in Dreamweaver.) In this case, you need to open the error window in your browser as you test the code and see if it identifies the error location to help you find it in your HTML editor

Trang 10

FIGURE 37.2

A JavaScript program viewed in Adobe Dreamweaver

Running your script

The easiest way to run a script is to double-click it in the Scripts panel within InDesign, but you also can simply double-click the script file; note that InDesign may need to be open Also, while you’re developing the script, you can run the script directly from the application in which you

Before you venture too far into scripting, you should review the JavaScript-related information provided with InDesign:

l JavaScript documentation and tools: Sun places the very technical JavaScript documentation

on its Web site at http://java.sun.com/javascript/index.jsp

l InDesign scripting documentation: The InDesign installation DVD contains a

2,000-plus-page PDF file that explains scripting for InDesign This document, although a bit on the nical side, is a valuable resource It includes an overview of JavaScript scripting and the object model, as well as a list of InDesign-specific scripting terms and scripting examples

tech-If you want still more information about JavaScript, several books are available, including Beginning

JavaScript, Fourth Edition, by Paul Wilton and Jeremy McPeak and JavaScript Bible, Seventh Edition, by

Danny Goodman et al (both from Wiley Publishing)

Getting More Information on JavaScript

Trang 11

InDesign become the active program, and then the actions you put in your script take place Voilà and congratulations! You can now call yourself a scripter without blushing That’s all there is to creating and running a script.

Saving your script

When you’re finished writing and testing a script, choose Save from the script editor’s File menu

Name your script and choose its storage location Move or copy the saved script to one of the two locations described earlier in this chapter

Exploring AppleScript

AppleScript is a scripting language developed by Apple and initially released with System 7.5 that can be used to control Macs, networks, and scriptable applications, including InDesign The AppleScript language was designed to be as close to normal English as possible so that average Mac users — specifically, those who aren’t familiar with programming languages — can understand and use it

Note

InDesign can run text-only AppleScripts in addition to compiled (binary) ones n

Learning the language

Many of the actions specified in AppleScripts read like sentences you might use in everyday versation, such as:

con-set color of myFrame to "Black"

or

se t applied font of myCharacterStyle to "Times"

What you need to write and run scripts

The script editor provided with the Mac OS lets you write scripts In Mac OS X 10.6 Snow Leopard, you find the AppleScript Editor inside the Utilities folder inside your Applications folder (at the root level of your hard drive) In Mac OS X 10.5 Leopard, you find the Script Editor inside the AppleScript folder inside your Applications folder

Note

Mac OS X 10.6 Snow Leopard calls the editor AppleScript Editor, whereas Leopard calls it just Script Editor

I use the general term script editor to refer to both They work the same way n

Trang 12

An uncompiled script is essentially a text file, so you can actually write scripts with any word cessor The script editor, however, was created for writing AppleScripts and includes several handy features for scriptwriters.

pro-Tip

To see what AppleScript commands InDesign supports, you can view the InDesign object model — the ported commands — within the script editor; just choose File ➪ Open Dictionary and then scroll to the

sup-InDesign application icon and click Open n

Checking for syntax errors

The next step is to determine whether the statements are correctly constructed Click the Check Syntax button If the script editor encounters a syntax error, it alerts you and highlights the cause

of the error If the script’s syntax is correct, all statements except the first and last are indented and

a number of words appear in bold, as illustrated in Figure 37.3 Your script has been compiled and

is ready to test

Running your script

To run a script from InDesign, click the script in the Scripts panel Alternatively, click the script file itself (InDesign may need to be open) When developing the script, click the Run button in the script editor; InDesign becomes the active program, and your script is running

double-Before you venture too far into scripting, you should review the AppleScript-related information vided with the Mac OS and with InDesign:

pro-l Mac scripting documentation and tools: Apple places the AppleScript documentation on its

Web site at www.apple.com/applescript In your hard drive’s Applications folder, you should have a folder called AppleScript that contains the Script Editor program, along with a folder of example scripts and the AppleScript Script Menu that adds the Script menu to the Finder Apple also offers a professional AppleScript editor called AppleScript Studio for download at its developer Web site, www.apple.com/macosx/features/xcode/ Apple makes AppleScript Studio part of its Xcode scripting tool, so you need to get Xcode to get AppleScript Studio

l InDesign scripting documentation: The InDesign DVD contains a 2,000-plus-page PDF file

that explains scripting, including AppleScript programming, for InDesign This document, although a bit on the technical side, is a valuable resource It includes an overview of Apple events scripting and the object model, as well as a list of InDesign-specific scripting terms and scripting examples

If you want still more information about AppleScript, several books are available, including AppleScript

by Mark Munro, and Beginning AppleScript, by Stephen G Kochan (both from Wiley Publishing).

Getting More Information on AppleScript

Trang 13

If you have trouble getting a script to run, double-check the name that InDesign uses for itself It might use InDesign® CS5 or simply InDesign® (yes, the name may include the registered trade-mark symbol) If you run a script from AppleScript (instead of just double-clicking it) and AppleScript can’t find InDesign, it gives you a dialog box with which you find the InDesign pro-gram When you’ve found and selected the InDesign application, AppleScript finds out what InDesign’s file name is and uses that in your script.

FIGURE 37.3

This script editor window contains sample AppleScript text

Saving your script

When you’re finished writing and testing a script, choose Save from the script editor’s File menu

Name your script, choose its storage location, and choose Compiled Script from the Format popup menu Move or copy the saved script to one of the two locations described earlier in this chapter

If you save the script in Application format and want to edit your script later, you must open it by dragging and dropping it on the script editor This is because Application-format scripts are designed to immediately run when double-clicked You would choose the Application format when creating scripts for use by others because chances are you don’t want them to open the script

in the script editor but instead simply use the script by double-clicking it like any other tion (It doesn’t matter whether the script is in Application format if you run it from InDesign’s Scripts panel.)

Trang 14

applica-Locating more AppleScript tools

A few software utilities are also available for AppleScripters The most widely used is Script Debugger, from Late Night Software ($199, www.latenightsw.com); it’s an interface develop-ment tool that quickly creates AppleScript-based applications that have the standard Mac look and feel Apple also offers its AppleScript Studio as a free download to developers who register at the Apple site (www.apple.com/macosx/features/xcode); this is more capable than the basic Script Editor that comes with Mac OS X AppleScript Studio is part of Apple’s Xcode scripting tool,

so you need to get Xcode to get AppleScript Studio

Exploring VBA

VBA, and its subset version VBScript, is Microsoft’s technology for writing your own programs, both those that run in other programs (scripts) and those that run by themselves (custom applica-tions) InDesign works with both VBA and VBScript The Visual Basic language that underlies both VBA and VBScript is not meant for everyday computer users; knowledge of programming is very useful in taking advantage of this technology Although based on the Basic language developed in the 1970s to help new users write their own programs, it has evolved a lot since then and is no longer so simple

Learning the language

Many of the actions specified in VBA have some degree of English, such as:

set myTextFrame = InDesign.Documents.Item(1).Spreads.Item(1)

TextFrames.Addor

mySelection.RotationAngle = 30

As you can see, that degree of English is slight The first code segment, for example, means to add

a text frame to the first spread in the first document The second means to rotate the selected object by 30 degrees

What you need to write and run scripts

To use InDesign scripting in Windows, you need Microsoft Visual Basic or an application that tains VBA; these include Microsoft Office, Microsoft Visio, and AutoCAD In Microsoft Office, you can run the Microsoft Script Editor by choosing Tools ➪ Macro ➪ Microsoft Script Editor, which lets you create scripts, edit them, test your code, and fix errors Figure 37.4 shows the editor with

con-a scon-ample script (Note thcon-at the script editor’s dicon-alog box hcon-as the self-importcon-ant ncon-ame Microsoft Development Environment rather than Microsoft Script Editor.)

Trang 15

l Microsoft scripting documentation and tools: Microsoft has a lot of information on VBA,

VBScript, and Visual Basic on its Web site Unfortunately, it’s not well organized and thus is hard to find and understand There’s no tutorial that simply explains how a new scripter needs to get started However, you can search on the Microsoft site for VBA, VBScript, and Visual Basic to get links to documents that may prove useful

l InDesign scripting documentation: The InDesign DVD contains a 2,000-plus-page PDF file

that explains scripting in InDesign, including VBA programming This document, although definitely on the technical side, is a valuable resource It includes an overview of VBA script-ing and the object model, as well as a list of InDesign-specific scripting terms and scripting examples

If you want still more information about VBA and its two sister technologies, several books are

avail-able, including VBScript Programmer’s Reference, Third Edition, by Adrian Kingsley-Hughes, Kathie Kingsley-Hughes, and Daniel Read; VBA For Dummies, Fifth Edition, by John Paul Mueller; and

Mastering Microsoft VBA, Second Edition, by Guy Hart-Davis (all from Wiley Publishing).

Getting More Information on VBA

Trang 16

You can also write scripts in VBScript, a VBA subset, in a text editor such as WordPad You need Microsoft’s free Windows Scripting Host (WSCRIPT.EXE), which is usually installed with Windows, and you can download it from Microsoft’s Web site.

There’s a third choice for your scriptwriting: You can also use the full Microsoft Visual Basic product

sup-select Adobe InDesign CS5 Type Library in the References dialog box and click OK n

Running your script

There are a few ways to run a VBScript You can double-click the script in the Scripts panel within InDesign or double-click the script file itself from a folder When developing scripts, you can run the script directly from the application in which you created a VBA or Visual Basic script, such as the Microsoft Script Editor (VBScripts can be run from the Scripting Host application.) In all these cases, InDesign becomes the active program, and your script is running

Saving your script

When you’re finished writing and testing a script, choose Save from the script editor’s File menu

Name your script and choose its storage location Move or copy the saved script to one of the two locations described earlier in this chapter

Creating and Running Scripts

At this point, I’m assuming that the appropriate scripting software is installed on your computer

If this is the case, you’re ready to begin For your first trick, you’re going to make InDesign roll over — sort of Actually, you’re going to rotate an EPS graphic First, you’ll prepare InDesign for its role Launch the program and then create a new document (do not select Automatic Text Frame) In the middle of the first page, place an EPS graphic Make sure that it remains active after you place it

Writing simple scripts

The following three scripts, taken from Adobe’s InDesign script examples, do the same thing in JavaScript, AppleScript, and VBA — they rotate an EPS graphic and its frame

Trang 17

All the scripts in this chapter are available for download at www.InDesignCentral.com Just cut and paste them from the text files into the appropriate scripting editor Adobe’s user forums are also a good place to go for scripting help n

Type the lines that follow this paragraph exactly as they’re written for the scripting language you’ve chosen Type a return character at the end of each line Note also the use of straight quotation marks instead of curly typesetter’s quotes (the script editor does this for you) Be very careful when you type the text: Typos are script killers

Note

In the code samples below, the ¬ symbol indicates where a line of code is broken to fit the page width; in the actual script, there would be no ¬ character, and the line that follows would be combined with the line that now ends in ¬ n

JavaScripts require you to set your own variables (the var statements) that define what the object

is (Here, myLink is used for each object, myEPS is the object that contains the EPS attribute, and myFrame is the parent frame containing the EPS graphic.) You work with those variables to see what their attributes are and then change those attributes

If you’re in an adventurous mood, try substituting the statement myFrame.rotationAngle=30; in the preceding script with each of the following statements:

myFrame.shearAngle = 30;

myFrame.verticalScale = 200;

Trang 18

If you want to get really fancy, combine all the myFrame statements into a single script so that you can use the script to make all the changes at one time.

AppleScript

tell applic ation "Adobe InDesign CS5"

activate set myPageItems to {EPS, oval, rectangle, polygon}

set mySelection to selection

if class of item 1 of mySelection is in myPageItems ¬ and (count mySelection) > 0 then

if class of item 1 of mySelection is EPS then set myFrame to parent of mySelection

else set myFrame to item 1 of mySelection end if

set rotation angle of myFrame to 30 end if

end tell

Note

Be sure that a document is open and that you have selected at least one frame of any type before starting the script Also in the script itself, make sure to type the name of your InDesign program exactly as it appears in the Finder Because you’re free to rename your program, the name may not match the name in the first line of the script n

If you’re feeling daring, try substituting the statement setrotationangleofmyFrameto30

in the preceding script with each of the following statements:

set shear angle of myFrame to 30set vertical scale of myFrame to 200Here again, you can get fancy by combining all the set statements into a single script so that you can use the script to make all the changes at one time

VBA

Dim myInDesign As InDesign.ApplicationSet myInDesign = CreateObject("InDesign.Application.CS5")Set mySelection = myInDesign.Selection

If TypeName(mySelection.Item(1)) = "EPS" Then mySelection.Parent.RotationAngle = 30

Else mySelection.RotationAngle = 30End If

You might satisfy your adventurous streak by substituting the statement mySelection

RotationAngle=30 in the preceding script with each of the following statements:

Trang 19

set the color of the current box to "Blue"

set the shade of the current box to 50set the width of the frame of the current box to 10set the box shape of the current box to ovular

Go to town if you want: Combine all the set statements into a single script so that you can use the script to make all the changes simultaneously

Tip

Perhaps you noticed the chain of command used in the preceding scripts First the script addresses InDesign, then the active document (layout), and finally the active frame If you understand this concept, you’ll be script- ing like a pro in no time n

Labeling items

As you can see from the examples in the previous section, scripts often refer to items by their type and location in the document But there’s another way to refer to objects that makes sure you can select an item precisely: You can label, or name, an item You do so in the Script Label panel (choose Window ➪ Utilities ➪ Script Label) The process is easy: Select the object and then type a name in the panel That’s it!

When writing scripts, you refer to the labeled object as follows In these examples, the label is

TargetFrame, and don’t worry that the samples seem to do different things — they in fact are

unre-lated examples, not variations of the same command

Set myAsset = myLibrary.Assets.Item("TargetFrame")

Writing conditio nal scripts

Some scripts simply automate a set of tasks in documents whose content is predictable But more often than not, documents differ, so you need conditional statements to evaluate certain things to see whether they are true before applying a script’s actions Otherwise, you get an error message when something turns out not to be true As a simple example, a script that does a search and replace needs to have a document open and a frame selected If no frame is selected, the script won’t know what to search, and the user gets an error message

Trang 20

The same issue arises for repeated series of actions, where you want the script to do something for all occurrences The script needs to know what to do when it can’t find any more such occur-rences As an example, look at the following script, which counts all open documents For it to work, at least one document has to be open, so the script checks first to see whether in fact any documents are open and then delivers an error message that the user can understand if none is open The rotate-EPS-graphic script earlier also used a conditional to make sure there was an EPS graphic in the document Notice that in all three scripting languages, you use the command if to set up such conditionals.

if myNumberOfDocuments = 0 then display dialog "No InDesign publications are open!"

end ifend tell

VBA

Dim myInDesign as InDesign.Application Set myInDesign = CreateObject ("InDesign.Application.CS4")

If myInDesign.Documents.Count MsgBox "No InDesign publications are open!"

End IfEnd Sub

Another form of conditional is what’s called a control loop, in which an action occurs either for a

specified number of iterations or until a condition is met The following scripts show an example

of each for each language Note the use of comments in the scripts — a handy way to document what you’re doing for later reference In JavaScript, a single-line comment begins with //, whereas

a multiline comment begins with /* and ends with */ In AppleScript, a comment begins with and continues until you press Enter or Return In VBA, it begins with Rem followed by a space, and it continues until you press Enter or Return

Trang 21

for (var myCounter = 0; myCounter < 20; myCounter++){

//do something}

while (myStop == false){

/* do something, at some point setting myStop to true

to leave the loop */

end repeat

VBA

For counter = 1 to 20 Rem do somethingNext counter

Do While myStop = false Rem do something, at some point setting myStop to true ¬

to leave the loop

loop

Summary

If your workflow goes beyond original designs for each client and reaches into repetitive tion, scripting is for you Scripts are ideal for automating repetitive tasks — from importing pic-tures to creating and formatting entire documents You can even link InDesign to other scriptable applications

produc-Because InDesign supports JavaScript on the Mac and Windows, as well as AppleScript on the Mac only and VBA on Windows only, you can choose the script language you’re most familiar with and/

or that is compatible with your other applications Even better, you can use more than one ing language with InDesign (though any individual script can use only one language)

Trang 23

script-Part X

Appendixes

IN THIS PARTAppendix A

Installing InDesign and Extensions

Appendix B

What’s New in InDesign CS5

Trang 25

Installing InDesign and Extensions

IN THIS APPENDIXUnderstanding CS5 system requirements

Installing InDesign CS5 Upgrading from prior versions

of InDesign Removing InDesign Managing plug-in software

Installing InDesign CS5 is surprisingly easy, but before installing or

upgrading, make sure your system meets the InDesign CS5 system requirements

Then use the steps in this appendix to make quick work of the installation process If you’re upgrading from an earlier version, you’ll actually perform a new installation, but read the section on upgrading near the end of this appendix for information about making the transition to InDesign CS5

Understanding InDesign CS5 System Requirements

InDesign CS5 does not require extraordinary resources If you have a Mac or

PC that runs one of the required operating systems, you can run InDesign CS5 Just be sure to have enough hard-drive space and memory to be able to work with large images, many fonts, and multiple projects as well, so that you can have additional applications, such as Adobe Photoshop, open at the same time

Here are the official requirements:

l For Mac systems, a multicore Intel processor, running Mac OS X version 10.5.7 (Leopard) or later or Mac OS X version 10.6 (Snow Leopard) Note that the drive you install InDesign CS5 on must not use the HFS file system from Mac OS 9 and earlier, so be sure to use the Mac OS Extended file format (the default on all Intel Macs) as the drive format

Ngày đăng: 24/12/2013, 15:16

TỪ KHÓA LIÊN QUAN

w