0 Replies Latest reply on Sep 18, 2009 8:14 AM by Dave Saunders

    Adding a Text Frame to an Existing Group

    Dave Saunders Level 4

      I have belatedly discovered another difference between CS4 and CS2 -- I don't know whether this started with CS3 or not; I think perhaps it did.


      When you want to add a text frame to an existing group (which means create a new one within group), it's fairly straightforward unless the group is inline to a story. Then the new item gets added at the wrong place (I suspect what actually happens is that it always used to get added at the wrong place and then moved to the specified coordinates; but in CS2 and earlier, there was no automatic updating of the screen so the coordinates worked, but in CS4, the addition of the new frame moves the inline and so the coordinates you're aiming for are no longer correct). I worked around this in the following script by changing the anchoring and then changing it back -- I'm not entirely sure that this is foolproof, but it works on the job we're using it for.

      //DESCRIPTION: Add New TF to Parent Group of Selected TF
      (function() {
           if (app.documents.length > 0 &&
                     app.selection.length === 1 &&
                     app.selection[0].parent instanceof Group &&
                     app.selection[0] instanceof TextFrame) {
           var group = app.selection[0].parent;
           if (group.parent instanceof Character) {
                // we have an anchored group. Make sure it is custom while processing
                var origAncState = group.anchoredObjectSettings.anchoredPosition;
                group.anchoredObjectSettings.anchoredPosition = AnchorPosition.anchored;
           var bounds = app.selection[0].geometricBounds;
           var newTF = group.textFrames.add({geometricBounds:bounds});
           newTF.move(undefined, [0, -1]); // offset a pica -- or whatever the units are
           if (origAncState !== undefined) {
                group.anchoredObjectSettings.anchoredPosition = origAncState;
           } else {
                alert("Please select a text frame in a group.");