Титульная страница
ISO 9000 ISO 14000
GMP Consulting
 
Mastering CorelDRAW 9

Previous Table of Contents Next


Advanced Scripting

If you go no further than the basics covered here, you will be well ahead of the game when it comes to coping with redundant and tedious tasks. Nonetheless, there are many other ways to take advantage of DRAW’s scripting tool while still stopping short of learning the programming language. Here are two of our favorites.

Turning a Script into a Command

What is the difference between one of your scripts and one of DRAW’s commands? On the surface, you can eliminate any difference at all. You can make one of your scripts look as if it were designed into the program by adding it to one of the menus or toolbars, or by assigning it to a hotkey. The next chapter gives a complete overview of customizing your environment and techniques for creating custom toolbars, menus, and hotkeys. In short, any command, any docker, any style, and any script can be added to the interface as a menu choice, an icon on a toolbar, a hotkey, or all three. This is the remote control of the Script Manager—it provides instant access to any script you create. Figure 33.3 shows the script we created earlier being assigned the hotkey of Ctrl+Shift+R.


FIGURE 33.3  Customization reaches nirvana: a custom script being given a custom hotkey.

Auto-scripting

You can create scripts that automatically execute whenever you start DRAW, start a new drawing, open an existing drawing, print, or close the program. These are very handy for any housekeeping that you seek to do on a regular basis, like, say, automatically setting guidelines, creating some boilerplate objects or text, or setting defaults. These are things you could store in templates, but it’s much easier to press Ctrl+N to get a new drawing than to do the New from Template dance.

The online Help offers a good rundown on auto-scripts, but it is completely buried, so with apologies to Corel, we are borrowing generously from it and including it here.

Auto-scripts are identified by their names and their locations. They must be placed in the Draw directory, not the Draw\Scripts directory. There are six auto-scripts, as follows:

OnStart Runs after DRAW is loaded and supersedes any other startup features that you may have selected. This means that you can write a script that replaces the Welcome to CorelDRAW dialog with a custom dialog, perhaps offering a menu of current DRAW projects.
OnOpen Runs after you open an existing drawing.
OnClose Runs before you close a document.
OnNew Runs every time you create a new drawing. Our lead author uses this one to automatically draw ellipses on the Guideline layer for creating CD labels.
OnPrint Runs when you start a print job, but before the print job is actually sent to the printer. For example, if you want to insert your name or copyright information in the lower-right corner of every drawing you print, you can write a script that inserts this information and save it as OnPrint.csc. Every time you trigger a print job in DRAW, this script will run before the print job is generated.
OnExit Runs when you exit DRAW. After the script terminates, DRAW closes.

You can try these out for yourself. Record a simple script, like one that creates a circle, and save it in the Draw directory as OnNew.csc. Then press Ctrl+N for a new drawing and note how that circle will appear out of nowhere.

If you do not want an auto-script to run, you can hold Shift while the particular event occurs (open, close, print, etc.). For instance, if you hold down Shift while DRAW is starting, OnStart will not run.

Choosing between a Style, aScript,and a Scrap

In many instances, styles, scripts, and the Scrapbook can be used interchangeably. If you want to color an object or group of objects blue, you can use any one of these three functions. Here are some tips for determining which tool is best for the task you need to get done.

Situations That Call for Styles

You have already created and formatted an object. A style works better here, because it can be created from an existing object. With a script, you would have to repeat all of the formatting steps to record them.
You want changes you’ve made to one object to affect other objects. If you anticipate that additional formatting changes will be needed in the future, you’re better off using a style. By changing one object and then updating the style, you automatically change the others. There is no similar global link with scripts.

Situations That Call for Scripts

You want to transform an object. Use a script here. In a script you can record all of the functions in the Transform docker. A style does not save these transformations.
You want to convert an object to curves. Again, we are talking about the recording of an action taken on the object, rather than applying a format to it. Styles can’t do that, but scripts can.
You want to create objects automatically. A script can actually create an object as part of its playback. A style cannot create objects.
You want to record a blend between two objects. Scripts can do that; styles can’t.
You like to add descriptions of the effect. The Scripts Manager allows you to store the name of the script, a description up to nine lines long, and a visual thumbnail of the result. In contrast, the Styles docker offers nothing more than the name of the style. If you find yourself forgetting what a style does and why you defined it in the first place, you might have better luck recording a script.

Situations That Call for the Scrapbook

The relatively new Scrapbook feature will take a bit of time to find its way into our hearts, not because it is poorly implemented, but because it is easily forgotten. But we have begun to respect its ability to act as a bone yard for drawings in progress. Use the Scrapbook when:

You want to add several elements to a drawing at once. You could use a script for this, but it’s much easier to just drag them out of the Scrapbook, as many times as you need copies of them. Of course, you need to add it to the Scrapbook in the first place, but once you do, you can create copies rapid-fire.
You realize, too late, that you did something perfect. Our lead author regularly exclaims, “Look, I did it—why wasn’t I recording it!” Then he remembers that he can take his work of art and drag it into the Scrapbook until he wants to use it again.
You’re just not sure what to do with it... Sometimes, it’s tedious to create, name, and store a script for an effect whose fate is unclear. But dragging it to the Scrapbook is very painless.


Previous Table of Contents Next
 
Rambler's Top100