Tag Archive for 'InDesign'

Getting to know Adobe PatchPanel

Adobe has a new way to easily create Actionscript / Flex apps that can deeply control the Creative Suite products.

PatchPanel is a library from Adobe Labs. It acts as a lightweight bridge between your Flex app and a CS3 / CS4 application. If you're used to Flex, this makes it really simple to quickly put together an interface, make a plugin and automate complex tasks.

Of course, you still need to learn what API calls to make to talk to your document.

A brief overview of the setup:

  1. Your project must include the PatchPanel SWC as an imported library.
  2. To run / deliver your plugin, the compiled swf must be put in the correct location in the Adobe host application directory, as well as a special JavaScript file that loads the swf into the host application.

For more detailed information on how to get started, see PatchPanel - Adobe Labs

InDesign API - Miscellaneous Tips

I have been making a plugin for InDesign the last few months. There is some documentation out there, but not a huge amount. The API document often has poor descriptions of methods, so it can became a bit of a guessing game. Here are a few words of wisdom to get you started.

Setting the Dimensions

The install JavaScript file allows you to set the width and height of your plugin. It should match the dimensions in your Application.mxml file. At first I was unsure why you would want to set this; the plugin ends up being whatever size specified in the mxml anyway. But what happens is, it initially loads at the size given in the JavaScript file, and then half a second later it RESIZES to the mxml values.

There is always a small gap of light grey space between the edge of your application and the actual edge of the window, about 3 pixels. I found this frustrating but could not find a way to avoid it. Furthermore, I noticed the right and bottom edges were a dark blue/grey instead of light grey. This was even more frustrating.

Eventually i figured out these darker edges only appear if the width and height given in the JavaScript install file are DIFFERENT from the width and height in the application mxml. The dark color is actually just the Flex default application background color. So I have settled with ensuring the specified dimensions match each other, and making my background color of my application a matching light grey.

The Document

From anywhere in your application, you can access the current document with:

Speed

Some properties are considerably slower to access than others. For example:

is much faster than

The latter will recursively search the hierarchy of page items and return a flat Array. If you are going to be calling it multiple times or in a loop, you are better off calling it once and storing the result.

PageItems have a property 'associatedXMLElement'. You can use this property to find how items are tagged in the document. But using it is also relatively slow (e.g. if you are doing it 100 times, you will notice it).

Stroke

I wanted to dynamically set the stroke width of a rectangle to different values. Whenever I set it to 0, it was invisible as expected, but when I set it back to say '3', it would NOT appear again. For the longest time I could not figure out why. Turns out, when you set stroke to 0 InDesign automatically sets the stroke color to 'None' for you, but when you set the stroke back to a number bigger than 0, the color stays as 'None.' (I don't know why, because this isn't how InDesign behaves as an application). So my workaround was to 'remember' what color the stroke used to be, and set it back manually myself.

Events

There is very poor / limited documentation on how to listen to InDesign events. Apparently you can register callback functions for certain events, but I could not get it working. Hopefully with the formal release of PatchPanel, this will all be documented more thoroughly.

Conclusion

I found PatchPanel very easy to get going with and accomplish most tasks. Its pretty cool when you start to realize just how much power and control it gives you; however, the occasional, seemingly simple task can become frustratingly time-consuming to figure out. But there is a forum out there, and with time I assume there will be more useful documentation.

Comments