Friday, January 13, 2006


Working on Selected Group

In the job I'm doing right now, I have a lot of grouped objects. I keep them in a library and plop them on to their appropriate pages as needed. Then, I run a script primarily to get the proper formatting on the group as a whole and its contents.

Here's a simple example:
//DESCRIPTION: Fix up Graphs

myDoc = app.activeDocument;

myGroup = app.selection[0];


function processGraph(theGroup) {
  var thePIs = theGroup.pageItems;
  for (var j = thePIs.length - 1; j >= 0; j--) {
    var myItem = thePIs[j].getElements()[0];
  if ( == "TextFrame") {
      myItem.textFramePreferences.ignoreWrap = true;
      myItem.textFramePreferences.firstBaselineOffset = FirstBaseline.leadingOffset;
    if ( == 0) {
    } else {
      myItem.blendMode = BlendMode.multiply;
This script falls into the quick & dirty category. I wrote it for a particular kind of group in a particular kind of document containing a specific object style. I don't bother to check that there is a document open nor that there is a selection. I just go ahead and do my thing.

But, after many uses, it occurred to me that more than 90% of the time, I run this script immediately after placing the group inline from the Library. This means that most of the time, I've been switching to the pointer tool and selecting the group before running the script. Finally, this morning, I realized that by adding:
if ( == "InsertionPoint") {
  var myStory = myGroup.parentStory;
  var myGroup = myStory.characters[myGroup.index - 1].groups[0];
to the script immediately after setting myGroup to point at the selection, I could avoid the need to switch pointer tools and let the script find the group -- again, I've done this in a quick and dirty fashion, relying on myself to remember the appropriate time to run the script and the state it expects.

You might be wondering why I would have a function to process the contents of the group. Why not just build the group right in the first place. Two reasons:
  1. The groups were prepared by a separate process on a different computer before all the details of how it would be used were fully worked out.
  2. Applying an object style to a group tends to mess up settings inside the group, so they have to be repaired even if they were right in the first place.

Comments: Post a Comment

<< Home

This page is powered by Blogger. Isn't yours?