Friday, August 26, 2005

 

Script of the Day -- Add Item to Group

I'm doing some corrections for a client. An element he wanted changing is a map where I had labeled North and South Carolina with callouts that sat over the states. The client asked me to move the names into the ocean (easy) and add pointers. How does one add pointers to an existing group? For that matter, how do you add anything to an existing group?

In the User Interface, the problem is close to insurmountable without taking the group apart, creating your new elements and regrouping. But for a script, all you have to do is add an element to the collection of like elements in the group (even if that collection is originally empty).

So, I composed this script:
//DESCRIPTION: Add Graphic Line to Parent Group 

if ((app.documents.length != 0) && (app.selection.length != 0)) {
 // Check that selected item is member of a group (start simple)
 mySel = app.selection[0];
 myGroup = mySel.parent;
 if (myGroup.constructor.name != "Group") {
  errorExit("Selection is not a member of a group");
 }
 myGMbounds = mySel.geometricBounds;
 myStroke = myGroup.graphicLines.add({geometricBounds:myGMbounds});
} else {
 errorExit();
}

// +++++++ Functions Start Here +++++++++++++++++++++++

function errorExit(message) {
 if (arguments.length > 0) {
  if (app.version != 3) { beep() } // CS2 includes beep() function.
  alert(message);
 }
 exit(); // CS exits with a beep; CS2 exits silently.
}

// +++++++ Script Ends Here ++++++++++++++++++++++++++

Comments:
I need to post some basic instructions on what to do with a script in order to use it. Here's my standard boilerplate:

To use the script, copy and paste to a text editor and save as a plain text file with an appropriate name in the form YourName.jsx in the Scripts folder of the Presets folder of your InDesign CS2 folder (you could put it in a subfolder if you wish). Then to run the script, double-click its name in the Scripts palette.
 
Post a Comment

<< Home

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