Posts tagged "events"

Working with Layers

Layers, in graphic arts programs, give you a way of organizing objects in your documents and controlling their front-to-back stacking order. Illustrator, InDesign, and Photoshop all have layers, and share most basic layer features: you can create, move, hide, and show layers, and you can assign objects to layers. Illustrator and Photoshop have the ability to create layers within layers—“layer sets” or “layer groups.”

As is usual, the scripting model differs among the applications, so I’ll provide a set of wrapper functions that will take the same parameters, regardless of the host application. I’ll put all of the application-specific details inside these functions. I’ll make the functions work for Photoshop layer groups and Illustrator sub-layers, as well as for InDesign’s simpler layers. I don’t want to rebuild each application’s Layers panels, so I’ll provide simple buttons for putting the layer functions through their paces. (It seems to me unlikely that you’ll want to re-create the Layers panel, and more likely that you’ll want to add/assign/move layers without displaying a user interface at all. If I’m dead wrong, please let me know!)

This example is even more basic than the previous one—but I found a number of points that might trip up developers trying to work with layers in their extensions.

You can find the example project here:

layers
Continue reading…

More Basics: Importing and Exporting Files

One of my co-workers (let’s call him “Zak”) recently referred to this series of blog postings as “an expanded Hello World.” Zak wasn’t being critical; he thinks this is a good thing, and I agree. The point is to get developers past the “what do I do now?” hump—the one that follows immediately after you’ve set up your development environment and worked through your first (usually trivial) tutorial example extension.

What I’m trying to do is make sure that new developers don’t get stuck because of some application-specific peculiarity of one of the Creative Suite applications. I know that this can happen, because it’s happened to me. Often.

In this post, we’ll turn back to the “Big Three” applications of the Creative Suite: Illustrator, InDesign, and Photoshop. All three applications can import, or “place” documents, and can export or save files in a wide variety of file formats. Each program has an idiosyncratic way of doing this basic task, so I’ll create a generic wrapper function and encapsulate (hide) all of the application-specific details.

This post follows in the footsteps of earlier posts, notably ”Drawing Paths,” ”Entering and Formatting Text,” and ”Watching the Detections,” and continues to build our basic Creative Suite SDK construction kit.

You can find the project for this example here:
importexport
Continue reading…

Putting It All Together: Path Effects

In these blog posts, I’m trying to create a series of “building blocks” that CS SDK users can put together to make CS Extensions. Need to draw things with your CS Extension? You can pull drawing routines from the “Drawing Paths: The Basics” post. Want to have your CS Extension respond to document open/close events? Grab the DocumentWatcher class from the “Watching the Detections” post.

At the same time, I’m thinking that some CS SDK users are coming to the Creative Suite without deep knowledge of at least some of the applications. A developer who has spent years working with Flash might not know (or want to know) the finer details of drawing paths in Illustrator, or setting type in InDesign.

My goal is to make it possible for these developers to get things done in Illustrator, InDesign, and Photoshop relatively quickly, without having to learn the document object model of each application (each one different). To that end, I’ve provided functions that encapsulate some of the complexity inside applications-specific functions.

Sadly, for this post, we’ll have to leave Photoshop behind, as that application doesn’t really provide a way to tell if a path is selected. (Or, I should say, it doesn’t provide an obvious way—I’m still looking.)

To see how this might work for you, let’s put together a new CS Extension using parts and pieces from my earlier blog posts. We’ll create an extension that applies various effects to the paths of page items selected in the host application, and we’ll get most of the code from the Drawing and DocumentWatcher projects.

This project also gives me a chance to make a point about Creative Suite Extensions in general: I think that we developers often think only in terms of productivity tools—writing XMP metadata or setting up defaults for a workgroup, that sort of thing. We tend to forget that automation can be used to add creative tools and new artistic effects.

The project for this example is here:

PathEffects
Continue reading…

Watching the Detections

Most of the time, Creative Suite extension panels will need to know something about the state of their host application. If the extension, for example, displays a pop-up menu containing a list of the layers in the current document, the extension will need to know when the document closes, or when a new document opens. When the extension detects that the current document has changed, it can do whatever it needs to do to repopulate the menu.

While you could monitor the state of the application using polling—a function in a timing loop that checks the state of the application every so often—it’s much better to use event listeners. Event listeners are triggered whenever a particular event takes place, and run a function that responds to that event in some way. The only trick is that the application you’re interested in working with has to provide some sort of notification that something has happened that’s relevant to your extension. As you’ll see, that’s not always as straightforward as it sounds.

Because CS extensions are built on top of CSXS (Adobe’s Creative Suite Extensible Services framework), they can make use of CSXS “standardized” events.

Event Name Event Triggers:
documentAfterActivate When you activate the document.
documentAfterDeactivate When you deactivate the document
 (i.e., when you bring another document to the front).
applicationBeforeQuit When you quit the application.
applicationActivate When you activate the application.
documentAfterSave Immediately after you save the document.
 

 

Not all Creative Suite applications support the full range of CSXS “standardized” events, but the applications I want to work with—Illustrator, InDesign, and Photoshop—all support the events I’m most interested in. These applications also support other events—later in this post, I’ll show you how to create event listeners for those application-specific events.

We’ll also use two other CSXS events: StateChangeEvent.WINDOW_OPEN and StateChangeEvent.WINDOW_SHOW. These events are not part of the ”standardized” CSXS events—they apply to the state of the panel window itself. For more on general CSXS events, refer to the “com.adobe.csxs.events” section of the CSXS Library API Reference.

To test our event listeners, we’ll get and display the layers in the current document, and we’ll update the list of layers every time a document changes. I’m thinking that this is something that many CS extension developers will want to do.

You can find the project at:

DocumentWatcher
Continue reading…

MakeSideHeads: A Complete InDesign CS5 Panel

The MakeSideHeads example (download link below) shows how to create a fully functional InDesign CS5 panel using the Creative Suite Extension Builder and the CSAW and host adapter libraries for InDesign.

This extension demonstrates:

  • How to use CSXS events and event listeners.
  • How to use the host adapter library for InDesign to monitor and respond to application-specific events (i.e., events that are outside of the standard CXSX events)
  • How to work with InDesign’s find text preferences from ActionScript
  • Reading and writing CSXS preferences
  • How to display a modal dialog box from a CS Extension
  • A number of InDesign scripting tricks

Download a Zip archive containing the project here:
makesideheads

Update: This project is now available via Import>Adobe Creative Suite Extension Builder>Remote Creative Suite SDK examples.

Continue reading…