Your prescription for increased productivity and profitability
Before we leave the subject of InCopy Workflows, we need to discuss working with images. Image workflows are often mixed: sometimes the designer places images, while on other occasions this chore may be left to a member of the editorial staff. No matter who places the images, it is the designer’s responsibility as part of laying out the pages to include image containers and caption frames. To automate the process, a script may be used to create these items.
Defining size and positioning for the image and caption page items can take on a life of their own. Consider the following:
One idea for automating images is to include the caption and credit as part of the image’s metadata (description and author fields). A script can then read the metadata and populate the caption frame as part of the process of placing the image.
Our sample script ImagePlaceholder has the user create a rectangle to indicate the placement and width of the image on the page. With the rectangle selected, the script is run using a keyboard shortcut. The script prompts the user to choose a file for placement. It then presents a simple dialog in which the user selects the size ratio for the image container, enters a name for the image, and indicates if the script should attempt to add contents to the text frame. It then creates the page items, names them using the name provided by the user, places the image, and adds credit and caption from the image’s metadata as needed.
If the designer decides to have the InCopy user place the image, the same script would be used only with a placeholder image and no caption. The image and caption frame are then included with the page item selection when the assignment script is run (AssignSelected).
The normal process for placing an image inside a container is to select the container and place the image. For InCopy, it is a little different, often causing concern with new users. Instead, let’s see how this could be automated.
Automating InCopy with scripts is similar to InDesign, but with one big exception: there are no frames. Or are there?
When you select an image in InCopy’s Layout view, you select the image, not its container. The question is then, how to get access to the container so it can place the image.
With a script, you have access to the container. It is the parent of the image. Using this knowledge plus the fact that the the image container and caption frame both have the same name, the script can be written. (Remember: the script that creates the placeholder image names both the image container and the text frame the same.)
The code following is the guts for the script PlaceImageWCap. It places the image, gets the image metadata, and populates the caption.
--calls to handlers to get references to the document and selected image set docRef to getDocRef() set imageRef to getSelection() --have user choose the file set imageToPlace to choose file with prompt "Select image for placing" --call to handler that does the work addContent (docRef, imageRef, imageToPlace) --Here is where all the work is done on addContent (docRef, imageRef, imageToPlace) tell application "Adobe InCopy CC" tell docRef set rectRef to parent of imageRef --be sure rectangle is checked out check out rectRef set rectName to name of rectRef --place the image tell rectRef place imageToPlace fit given center content end tell --add caption set frameRef to text frame rectName --has same name as image container set storyRef to parent story of frameRef set placedImage to image 1 of rectRef set linkRef to item link of placedImage set linKM to properties of link xmp of linkRef set capStr to "" if author of linkM is not "" then set capStr to capStr + author of linkM & return end if if description of linkM is not "" then set capStr to capStr & description of linkM end if set contents of storyRef to capStr set applied paragraph style of paragraph 1 of storyRef to "Credit" set applied paragraph style of paragraph -1 of storyRef to "Caption" end tell end tell end addContent
//calls to handlers to get references to the document, selected image, and chosen image file var docRef = getDocRef(); var imageRef = getSelection(); var imageToPlace = chooseFile_extTest ("Select Image file", "*.psd", [".PSD", ".JPG"], false); addContent (docRef, imageRef, imageToPlace); //call to handler that does the work function addContent (docRef, imageRef, imageToPlace){ var creditStyle = docRef.paragraphStyles.itemByName("credit"); var captionStyle = docRef.paragraphStyles.itemByName("caption"); var rectRef = imageRef.parent; //make sure container is checked out rectRef.checkOut(); var rectName = rectRef.name; rectRef.place(imageToPlace); //add caption var frameRef = docRef.textFrames.itemByName(rectName); var placedImage = rectRef.images.item(0); var linkRef = placedImage.itemLink; var capStr = ""; if (linkRef.linkXmp.author != "") { capStr += linkRef.linkXmp.author + "\r"; } if (linkRef.linkXmp.description!= "") { capStr += linkRef.linkXmp.description } var storyRef = frameRef.parentStory; storyRef.contents = capStr; storyRef.paragraphs.item(0).appliedParagraphStyle = creditStyleName; storyRef.paragraphs.lastItem().appliedParagraphStyle = captionStyleName; }
Add error handling and subroutines (handlers and functions) to the code above and you can have a working script. Make sure you assign it to a keyboard shortcut and your InCopy users will love you. Watch for these scripts to be added to the InCopy Workflow collection. Modify the scripts for your own purpose and make the hassle of adding images and captions to your InCopy workflows a thing of the past.