InDesign Programming Guide

The basic process of connecting with InDesign and creating objects in a page layout is shown in the "HelloInDesign" example, available through the Extension Builder Remote Example Importer; see Importing and running the samples in the Getting Started Guide. This guide provides an overview of the InDesign document object model (DOM), an introduction to the techniques you use to manipulate InDesign documents, and a set of examples that illustrate particular tasks.

Custom menus in InDesign

The menu items for extensions that you create with Adobe Creative Suite Extension Builder can only be shown in the menu Window > Extensions. If you want to start your extension from another menu, you can do so using an InDesign C++ plug-in. Your C++ menu plug-in must launch your Flash-based extension using the C++ PlugPlug API. To prevent your extension from being displayed in the Window > Extensions menu, remove the menu name from the extension manifest.

For information on how to create a custom menu placement plug-in and how the plug-in can talk to your extension see the InDesign SDK (http://www.adobe.com/devnet/indesign/sdk/). .

Once you have created both the C++ plug-in and Flash-based components of your extension, bundle them together for distribution as a hybrid extension. For details, see the Signing and Packaging Toolkit, which you can download from the Adobe Creative Suite SDK page, http://www.adobe.com/devnet/creativesuite/.

 CSXS Events and InDesign

You can register for events using the IDHostAdapter library and C++ plug-in. These components are available as part of the Adobe Creative Suite Extension Builder. See Host Adapter Libraries for information on how to set up your Adobe Creative Suite extension to use this technology.

InDesign supports these CSXS  events:

Event

Description

documentAfterActivate

Triggered when a document has been activated.

documentAfterDeactivate

Triggered when the active document has been deactivated.

applicationBeforeQuit

Triggered when the application gets the signal to quit.

applicationActivate

Triggered when the application gets an "activation" event from the operating system.

documentAfterSave

Triggered after the document has been saved

InDesign-specific events (such as "selectionChanged") are not yet supported.

You can make use of the CSXS events to update the state of user interface controls or perform other tasks. For example, it is much more efficient to monitor the state of the application using CSXS events than to poll the state with a timer routine.

Here’s a code snippet that makes use of some of the CSXS events. This function runs when the extension starts up and installs event listeners for specific events. Buttons in the extension’s user interface are bound to the state of the myDocumentOpen variable in the "model" module, and are enabled or disabled depending on whether a document is open or not.

public function start():void {
   var myCSXS:CSXSInterface = CSXSInterface.getInstance();

   //Add an event listener for CSXS "Standard" events.
   myCSXS.addEventListener("documentAfterActivate", myEventHandler);
   myCSXS.addEventListener("documentAfterDeactivate", myEventHandler);
   myCSXS.addEventListener("applicationActivate", myEventHandler);
   myCSXS.addEventListener(StateChangeEvent.WINDOW_OPEN, myEventHandler);
   myCSXS.addEventListener(StateChangeEvent.WINDOW_SHOW, myEventHandler);

   controller.myUpdateControls();
}

The event handler itself includes some special case code to handle the "documentAfterDeactivate" event. Because this event fires just before the document is closed, we need to add a slight delay to let the document close fully before we attempt to update the user interface controls.

private function myEventHandler(event:CSXSEvent):void
{
   if(event.type == "documentAfterDeactivate") {

      //Need a slight delay here.
      var myTimer:Timer = new Timer(1000, 1);

      myTimer.addEventListener("timer", myTimerHandler);
      myTimer.start();
   }
   else {
      controller.myUpdateControls();
   }
}

private function myTimerHandler(event:TimerEvent):void
{
   controller.myUpdateControls();
}

The controller module contains the following code for handling the user interface updates:

public function myUpdateControls():void
{
   InDesignSample.myUpdateButtons();
}

The InDesignSample module contains the myUpdateButtons function:

public static function myUpdateButtons():void
{
   if((app.documents.length != 0)&&(model.myDocumentOpen == false)) {
      model.myDocumentOpen = true;
   }
   else if ((app.documents.length == 0)&&(model.myDocumentOpen == true)) {
      model.myDocumentOpen = false;
   }
}

 

 

 

Copyright © 2011 Adobe Systems Incorporated. All rights reserved.