Friday, December 22, 2006


Cut Contents

Every now and then a FreeHand user will pine for its Cut Contents command. This allows FreeHand users to select a frame that is serving as a mask by virtue of a previous Paste Into command. InDesign's user interface actually makes this fairly easy to achieve.
  1. With the selection tool (black pointer), select the frame.
  2. In the Control palette, click the Select Contents button.
  3. Choose Edit/Cut, or use the keyboard shortcut for Cut.
But most users seem to take a long time to discover those selection buttons in the Control palette. They also seem to be unaware of the equivalent functionality on the Select submenu of the Object menu. And so, if they're familiar with FreeHand, they search in vain for the Cut Contents command.

The topic came up again this morning on the U2U forum where I posted a simpler version of the script below. See:

As you can see in that posting, I immediately realized there was a problem if the user ran that version of the script with text selected. As the day wore on, I realized that groups and xmlElements also are problematic, so I ended up with this version of the script:
//DESCRIPTION: Cut Contents

Object.prototype.isIneligible = function() {
    case "InsertionPoint":
    case "Character":
    case "Word":
    case "TextStyleRange":
    case "Line":
    case "Paragraph":
    case "TextColumn":
    case "Text":
    case "TextFrame":
    case "Group" :
    case "XMLElement" :
      return true;
    default :
      return false;

if (app.documents.length == 0 || app.selection.length != 1 || app.selection[0].isIneligible()) { exit() }

function processSelection(sel) {
  try {[0])
    app.cut();  } catch(e) {
    alert("Selected item has no contents")
I keep telling myself that one of these days I'll script the equivalent of FreeHand's Attach Type to Path command, particularly the variation where a two-line text is attached to the top and bottom of an ellipse.

Friday, December 08, 2006


Story on Live Pages

I'm working with a document that has a lot of busy master spreads. But what I needed was to identify a particular story on the live pages. The frames are labeled, but so are the original frames on the master pages. So, it occurred to me to wonder if I could easily get a list of all the frames on the live pages of a document, ignoring the ones on the master pages.

Turns out that a double-dose of everyItem() gets the job done:
myFrames = doc.pages.everyItem().textFrames.everyItem().getElements();
This produces an array of all the text frames free-standing on the live pages of a document. So, I can examine that list to find the story of interest without having to be concerned about the master frames that have the same label.

Speaking of labeling, I used this in a function that records the identity of the story of interest in a document label, so that the story only has to be found once:
  function getMainStory(doc) {
    var label = doc.extractLabel("Main Story")
    if (label != "") {
      return doc.stories.itemByID(Number(label));
    } else {
      var myFrames = doc.pages.everyItem().textFrames.everyItem().getElements();
      for (var j = myFrames.length - 1; j >= 0; j--) {
        if (myFrames[j].extractLabel("Frame Type") == "Main Story Frame") {
          var myStoryID = myFrames[j];
          doc.insertLabel("Main Story", String(myStoryID));
          return doc.stories.itemByID(myStoryID)
  } // end getMainStory
I'm not fully convinced that this is the most efficient way of achieving this goal, but it works and after the first time, it is very quick.

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