Chapter w4: CREATOR2 FOR IMAGES

Multi-Ad's Creator2 is the most impressive, accessible, and out-of-the-box AppleScriptable graphics software available. Only PhotoScripter coupled with Photoshop can compete. We've already looked at another scriptable contender, B&E's RagTime, in Chapter w2.

Whereas RagTime shines in its wide-ranging integration of all sorts of functionalities, Creator2 focuses on graphics and publishing features that put it in the same league as Adobe Illustrator and Quark XPress.In this chapter, we'll create and export custom graphics, and batch produce mastheads and rollover graphics. We'll also create customized PDF files using Adobe Acrobat Distiller 3.0.

Scripting Creator2

Creator2 supports the placement and export of TIFF, EPS, GIF, and JPEG files, along with advanced font and graphics capabilities, thanks to its use of the GX graphics libraries that formed the heart of Apple's QuickDraw GX. Creator2 does not require you to install QuickDraw GX. The GX library has been integrated with the application as a shared library file.

Everything is recordable and scriptable in Creator2. The application is also attachable, with its own script menu. Using the script menu, you can run a script from within the application. This way you can easily apply scripts to the current selection and continue working seamlessly. Figure w4.1 shows Creator2's script menu.

Scripting graphics


 
Fig. w4.1  Creator2's Script menu, showing many of the standard AppleScripts that the program ships with. Each script can executed immediately from within Creator2 simply by selecting it from the menu.

Scripting Creator2

All the scripts that follow were designed and tested for Creator2 1.1.2.Creator2 is published by Multi-Ad, Inc., who can be reached at http://www.multi-ad.com/.

Recording scripts in Creator2

In this section, we'll experiment with recording actions in Creator2. Launch Creator2 and the Script Editor. Now bring the Script Editor to the front and follow the steps below to begin recording your graphic creations! Code w4.1 displays the script created by these actions. Figure w4.2 shows the final document that results from these steps.

To record your activities in Creator2:

  1. Start recording in the Script Editor.

  2. Open a new document in Creator2 without facing pages.

  3. Draw a rectangle on the page.

  4. Set the fill color to red and the line color to black.

  5. Now rotate the rectangle, skew it, and flip it around a bit.

  6. Bring the Script Editor to the front. You should see a script similar to Code w4.1 in the recording window.

Code w4.1. This sample script is the result of recording actions in Creator2 with the Script Editor.

tell application "Multi-Ad 
Creator2 1.1.2"
activate
make new document at
beginning with properties
{page count:1, first page
number:1, default size:
{class:GX point, x:576.0,
y:751.96}, facing pages:false,
make default master
spread:false}
make new rectangle
element at beginning of
spread 1 of document 1
with properties {bounds:
{class:GX rectangle, top:66.0,
left:121.0, bottom:115.0,
right:313.0}}
select {element 1 of
spread 1 of document 1}
set fill color of selection
of spread 1 of document 1
to "Red"
select {element 1 of
spread 1 of document 1}
set frame color of selection
of spread 1 of document 1
to "Black"
set rotation of element
1 of spread 1 of document
1 to 48.752059936523
select {element 1 of
spread 1 of document 1}
move selection of
spread 1 of document
1 by {class:GX point,
x:50.0, y:28.0}
set skew angle of
element 1 of spread
1 of document 1 to
66.34351348877
flip horizontally
element 1 of spread
1 of document 1
set properties of
element 1 of spread 1
of document 1 to
{location:{class:GX point,
x:284.268, y:154.35},
rotation:-13.701}
end tell

Fig. w4.2  Our sample document shows our original rectangle that we created in step 3, now contorted and warped by our actions in step 5.

Creating and exporting graphics and text

With script recording, writing scripts gets easier. The task becomes editing recorded code rather than writing scripts from scratch. Code w4.2 is easy to make by borrowing lines from Code w4.1's recorded code. Here, we'll create graphical text and objects with precision and control. Figure w4.3 shows the results of running our script.

To create and export graphics and text in Creator2:

  1. tell application "Multi-Ad Creator2 1.1.2" activate make new document at beginning with properties {page count:1, first page number:1, default size:{class:GX point, x:576.0, y:751.96}, facing pages:false, make default master spread:false}

    We begin by bringing Creator2 to the front and having it create a new letter-size document without facing pages or a default master spread.

  2. make new path element at beginning of spread 1 of document 1 with properties {bounds:{class:GX rectangle, top:94.748, left:117.0, bottom:121.0, right:206.0}, closed:true, control points:{{{location:{class:GX point, x:117.0, y:69.0}, smoothed:true}, {location:{class:GX point, x:206.0, y:121.0}, smoothed:false}, {location:{class:GX point, x:117.0, y:120.0}, smoothed:false}}}}

    Next, we create a freehand polygon path element with three points. We smooth one point to generate a Bezier curve by setting the point's smoothed property to true.

  3. select {element 1 of spread 1 of document 1} set fill color of selection of spread 1 of document 1 to "Red" set frame color of selection of spread 1 of document 1 to "None"

    We then select the path element and set its fill color to red and frame color to none.

  4. duplicate selection of spread 1 of document 1 copies 1 offset {class:GX point, x:-5.0, y:-5.0} without link text blocks

    Now, we duplicate the path element with a ­5 point offset in both the X and Y coordinates.

  5. make new rectangle element at beginning of spread 1 of document 1 with properties {bounds:{class:GX rectangle, top:102.0, left:115.0, bottom:120.0, right:163.0}, fill color:"None", frame color:"None"} make new text flow at beginning of document 1 with properties {textblock list:{element 1 of spread 1 of document 1}} select insertion point before text flow 1 of document 1

    We make a text flow inside of a rectangle and move the insertion point to the beginning of the text flow.

  6. set text selection of document 1 to "Get" select every character of text flow 1 of document 1 set font of text selection of document 1 to "Arial Black" set color of text selection of document 1 to {class:tint info, color:"White"}end tell

    Finally, we set the text of the flow to "Get" and change its font and color.

Code w4.2. This script creates a new document and draws some objects and text.

tell application "Multi-Ad 
Creator2 1.1.2"
activate
make new document at
beginning with properties
{page count:1, first page
number:1, default size:
{class:GX point, x:576.0,
y:751.96},
facing pages:false, make
default master spread:false}
make new path element
at beginning of spread 1
of document 1 with properties
{bounds:{class:GX rectangle,
top:94.748, left:117.0,
bottom:121.0, right:206.0},
closed:true, control points:
{{{location:{class:GX point,
x:117.0, y:69.0}, smoothed:true},
{location:{class:GX point,
x:206.0, y:121.0}, smoothed:false},
{location:{class:GX point,
x:117.0, y:120.0},
smoothed:false}}}}
select {element 1 of spread
1 of document 1}
set fill color of selection
of spread 1 of document 1
to "Red"
set frame color of selection
of spread 1 of document 1
to "None"
duplicate selection of
spread 1 of document 1
copies 1 offset {class:GX
point, x:-5.0, y:-5.0} without
link text blocks
select {element 1 of spread
1 of document 1}
set frame color of selection
of spread 1 of document 1
to "None"
set fill color of selection
of spread 1 of document 1
to "Black"
make new rectangle
element at beginning of
spread 1 of document 1 with
properties {bounds:{class:GX
rectangle, top:102.0, left:115.0,
bottom:120.0, right:163.0},
fill color:"None", frame
color:"None"}
make new text flow at
beginning of document 1
with properties {textblock list:
{element 1 of spread 1 of
document 1}}
select insertion point
before text flow 1 of
document 1
set text selection of
document 1 to "Get"
select every character
of text flow 1 of document 1
set font of text selection of
document 1 to "Arial Black"
set color of text selection
of document 1 to {class:tint
info, color:"White"}
end tell

Fig. w4.3  After our script has run, we will have a new document that contains these 2 unusual looking polygonal shapes as well as the text we specified in step 6.

Batch producing repeating elements like mastheads

Once you've mastered the scripting of object creation and modification, batch production of graphic elements is the next natural step. This script (Code w4.3) produces a series of exported TIFF files at double resolution (144 dpi) based on the currently open file, which the script expect to contain at least two text elements. If you want to use these files on the Web, you'll need to subsequently batch convert and scale them in another program or with another script. Figure w4.4 shows a sample screen that might appear while the script is running. Make sure you create a sample masthead file with two text elements in it before running this script.

To batch produce repeating elements like mastheads:

  1. set myTitles to {"About Us", "Company History", "Press Room", "Products"}set mySubtitles to {"Learn more about us", "Read about our amazing past", ¬ "The latest news about us", "Our products speak for themselves"}

    We set a list to hold our title strings and a list to hold our subtitle strings.

  2. set myFolder to (choose folder with prompt "Folder to save images:")

    We set a list to hold our title strings and a list to hold our subtitle strings.

  3. tell application "Multi-Ad Creator2 1.1.2" activate repeat with i from 1 to the number of items in myTitles

    Next, we bring Creator2 to the front and start a repeat loop through all the title items.

  4. select every character of text flow 2 of document 1 set text selection of document 1 to (item i of myTitles)

    We select the text of our text flow for the title and set it to the text of the current item in our titles list.

  5. select every character of text flow 1 of document 1 set text selection of document 1 to (item i of mySubtitles)

    We select the text of our text flow for the subtitle and set it to the text of the current item in our subtitles list.

  6. select every element of spread 1 of document 1

    Now we select all the objects on the page.

  7. set myFile to myFolder & "masthead-" & i as text

    We set a variable to hold the file name for the current graphic.

  8. export TIFF selection of spread 1 of document 1 saving in file myFile export depth use millions of colors export resolution use 144 dpi end repeatend tell

    Finally, we export a TIFF containing the current selection to our new file at double resolution (144 dpi).Code w4.3 This script batch produces masthead graphics.

Code w4.3. This script batch produces masthead graphics.

set myTitles to {"About Us", 
"Company History", "Press
Room", "Products"}
set mySubtitles to {"Learn
more about us", "Read
about our amazing past",
"The latest news about us",
"Our products speak for
themselves"}
set myFolder to (choose
folder with prompt
"Folder to save images:")
tell application "Multi-Ad
Creator2 1.1.2"
activate
repeat with i from 1 to the
number of items in myTitles
select every character
of text flow 2 of document 1
set text selection of
document 1 to (item i of
myTitles)
select every character
of text flow 1 of document 1
set text selection of
document 1 to (item i of
mySubtitles)
select every element of
spread 1 of document 1
set myFile to myFolder
& "masthead-" & i as text
export TIFF selection of
spread 1 of document 1
saving in file myFile export
depth use millions of colors
export resolution use 144 dpi
end repeat
end tell

Fig. w4.4  Once our script has run, you will have a document that might look something like this. The script changes the contents of the two text boxes and leaves all other objects alone.

Batch producing multi-state graphics like rollovers

Multi-state graphics are graphics whose appearance changes in different situations. Batch production of multi-state graphics like rollovers becomes easy with AppleScript. Rollover graphics are those images on the Web that change in response to a user's actions, like rolling over a button, hence the name. We can script the creation of all variations for a series of elements quickly and easily. Code w4. 4 produces a series of exported TIFF files at double resolution (144 dpi) based on a navigation button. If you want to use these files on the Web, you'll need to subsequently batch convert them in another program or with another script. Figure w4. 5 shows a sample screen that might appear while the script is running. Once your script has run, you'll need to batch convert the files for web use in another program.

To batch produce multi-state elements like rollover graphics:

  1. set myTitles to {"About Us", "Company
    History", "Press Room", "Products"}
    set myNormTextColor to "Blue"
    set myOverTextColor to "Green"
    set myCurrTextColor to "Red"
    set myNormDotColor to "White"
    set myOverDotColor to "Green"
    set myCurrDotColor to "Red"

    We begin by setting our list of title text elements and color settings for the three different states we will produce variations for: normal, mouseover, and current. In Table w4. 1 you can see the variable names that we are setting for the colors in various states.

  2. set myFolder to (choose folder with prompt "Folder to save images:")

    Now we prompt the user to select a folder to save the images into.

  3. tell application "Multi-Ad Creator2 1.1.2"
    activate
    repeat with i from 1 to the number of items in myTitles

    We bring Creator2 to the front and start our repeat loop through each of the items in the titles list.

  4. select every character of text flow 1 of document 1
    set text selection of document 1 to item i of myTitles

    Now, we set the text of our shadow text flow to the text of the current item in the titles list.

  5. select every character of text flow 2 of document 1

    We select the text of our frontmost text flow.

  6. set color of text selection of document 1 to {class:tint info, color:myNormTextColor}

    We then set the text color of the frontmost text flow to the normal state color.

  7. set text selection of document 1 to item i of myTitles

    Finally, we set the text of the frontmost text flow.

  8. select {element 1 of spread 1 of document 1}
    set fill color of selection of spread 1 of document 1 to myNormDotColor

    We select the oval and set its fill color to the normal state color.

  9. select every element of spread 1 of document 1

    Now, we select every object on the page.

  10. set myFile to myFolder & "button-" & i & "-norm" as text

    Here we set up our file name in the variable myFile.

  11. export TIFF selection of spread 1 of document 1 saving in file myFile export depth use millions of colors export resolution use 144 dpi

    Then we export of the current selection as a TIFF to our new file at 144 dpi.

Code w4.4. The script batch produces multi-state rollover graphics.

set myTitles to {"About Us", 
"Company History", "Press
Room", "Products"}
set myNormTextColor
to "Blue"
set myOverTextColor
to "Green"
set myCurrTextColor
to "Red"
set myNormDotColor
to "White"
set myOverDotColor
to "Green"
set myCurrDotColor
to "Red"
set myFolder to (choose
folder with prompt "Folder
to save images:")
tell application "Multi-Ad
Creator2 1.1.2"
activate
repeat with i from
1 to the number of
items in myTitles
select every character
of text flow 1 of document 1
set text selection of
document 1 to item i of
myTitles
select every character
of text flow 2 of document 1
set color of text selection
of document 1 to
{class:tint info,
color:myNormTextColor}
set text selection of
document 1 to item i of
myTitles
select {element 1 of
spread 1 of document 1}
set fill color of selection
of spread 1 of document 1 to
myNormDotColor
select every element of
spread 1 of document 1
set myFile to myFolder
& "button-" & amp;i &
"-norm" as text
export TIFF selection of
spread 1 of document 1
saving in file myFile
export depth use millions
of colors export resolution
use 144 dpi
select every character
of text flow 2 of document 1
set color of text selection
of document 1 to {class:tint
info, color:myOverTextColor}
select {element 1 of spread
1 of document 1}
set fill color of selection
of spread 1 of document 1 to
myOverDotColor
select every element of
spread 1 of document 1
set myFile to myFolder
& "button-" & i &
"-over" as text
export TIFF selection
of spread 1 of document 1
saving in file myFile export
depth use millions of colors
export resolution use 144 dpi
select every character
of text flow 2 of
document 1
set color of text selection
of document 1 to {class:tint
info, color:myCurrTextColor}
select {element 1 of spread
1 of document 1}
set fill color of selection
of spread 1 of document 1 to
myCurrDotColor
select every element of
spread 1 of document 1
set myFile to myFolder
& "button-" & i &
"-curr" as text
export TIFF selection of
spread 1 of document 1
saving in file myFile export
depth use millions of colors
export resolution use
144 dpi
end repeat
end tell


 

Fig. w4.5  Here we see a sample iteration of our rollover graphic as its being produced by our script. The colors of the 2 text objects and the graphic are set by our script, as well as the text contents of the 2 text objects.

Creating custom PDF files

This script (Code w4.5) modifies an open document in Creator2 by adding a text element to it, then exports the document temporarily as an EPS file. It then launches Acrobat Distiller to convert the EPS to a PDF. Finally, the script has the Finder delete the EPS file. Figure w4. 6 shows our document in Creator2 after the script has added the name text.

To create custom PDF files:

  1. set myText to text returned of (display dialog "Person's name" default answer "")

    We begin by prompting the user for a person's name.

  2. make new rectangle element at beginning of spread 1 of document 1 with properties ¬ {bounds:{class:GX rectangle, top:14.0, left:7.0, bottom:38.0, right:202.0}, fill color:"None", frame color:"None"}

    These lines ask Creator2 to make us a rectangle at the beginning of a new spread. We specify that the object is of the GX rectangle class (most graphic shape names are preceded by "GX" because Creator2 uses the GX library) and that it has no fill color or frame color, as well as telling Creator2 what coordinates to use.

  3. make new text flow at beginning of document 1 with properties {textblock list:{element 1 of spread 1 of document 1}}

    We now make the rectangle hold a text flow, which is a container to hold lines of text, like a text box in Quark XPress.

  4. select insertion point before text flow 1 of document

    We have to make sure we tell Creator2 where to put the insertion point, or we may end up editing just anywhere.

  5. set text selection of document 1 to myText

    Now, we set the text of the text flow to the name entered by the user.

  6. select every character of text flow 1 of document 1 set font of text selection of document 1 to "Palatino Regular"

    Then we set the new text's font to Palatino.

  7. set myFileName to get name of document 1 set myDesktop to (path to desktop folder) as text set myExportFile to myDesktop & myFileName & ".EPS"

    Now we create a new file name for the EPS file we're going to create.

  8. set myPDFFile to myDesktop & myFileName & ".PDF") as text

    Next we create a new file name for the PDF file we'll end up with.

  9. export EPS current spread of document 1 saving in file (myExportFile)end tell

    Then we export the current page to an EPS file with the file name from step 7.

  10. tell application "Acrobat Distiller 3.01" with timeout of 600 seconds open alias myExportFile destination file myPDFFile with wait end timeoutend tell

    Now we have Acrobat Distiller convert the EPS file to a PDF file using the file name from step 8. We let Distiller have 10 minutes (600 seconds) to complete the PDF creation by using with timeout.

  11. tell application "Finder" delete file myExportFileend tell

    Finally, we have the Finder delete the EPS file, since all we want is the PDF version.

Code w4.5. This script adds text to a Creator2 document, then exports it as an EPS and converts it to a PDF file.

set myText to text 
returned of (display
dialog "Person's name"
default answer "")
tell application "Multi-Ad
Creator2 1.1.2"
make new rectangle
element at beginning of
spread 1 of document
1 with properties
{bounds:{class:GX
rectangle, top:14.0,
left:7.0, bottom:38.0,
right:202.0}, fill color:
"None", frame color:
"None"}
make new text flow
at beginning of document
1 with properties
{textblock list:{element
1 of spread 1 of
document 1}}
select insertion point
before text flow 1 of
document 1
set text selection of
document 1 to myText
select every character
of text flow 1 of document 1
set font of text selection
of document 1 to "Palatino
Regular"
set myFileName to get
name of document 1
set myDesktop to (path
to desktop folder)
as text
set myExportFile to
myDesktop & myFileName
& ".EPS"
set myPDFFile to
myDesktop & myFileName
& ".PDF"
export EPS current
spread of document 1
saving in file (myExportFile)
end tell
tell application "Acrobat
Distiller 3.01"
with timeout of
600 seconds
open alias
myExportFile
destination file
myPDFFile with wait
end timeout
end tell
tell application "Finder"
delete file myExportFile
end tell

Fig. w4.6  Our sample document shows the text added by steps 2 through 6 of our script, in this case, "John Doe". The script adds this text to a pre-existing Creator2 document before making a PDF file.

Scripting Adobe Acrobat Distiller

Adobe Acrobat Distiller 3.01 is published by Adobe Software, Inc., who can be reached at http://www.adobe.com/.