7 Replies Latest reply on Sep 16, 2010 11:21 PM by Marijan Tompa [tomaxxi]

    CS5 - Can't get reference to frame in group

    Pet Re

      I'm writing a script to place a caption frame (textFrame) back underneath a graphic frame (Rectangle) after one of them has been manually resized or moved on the page. The frames are grouped. To adjust one of them I simply double click the required frame. When finished, I manually select the graphic frame and start the script to reunite both frames.This generates an error when the script gets to the line that sets the geometricBounds for myCaptionFrameY1: object is not valid.

      If I manually ungroup the frames, the script works just fine.

      I'm confused, because the CS5 Script reference states (page 59) that there is no need to ungroup if you want to change page items in the group (but maybe that doesn't include the textframe).


      //left out the myDoc etc.

      //this is the manually selected graphic frame, constructor=rectangle
      var myImageFrame = app.selection[0];

      //the name has been set in another script that generates the graphic and the caption frame

      var myImageFrameName = myImageFrame.name;

      var myCaptionFrame = myDocument.textFrames.item("cap" + myImageFrameName); //the result (alert) is an object textFrame

      //get the bottom of the graphic frame
      var myImageFrameY2 = myImageFrame.geometricBounds[2];

      //get the top of the caption frame

      //this line generates the error: object is not valid
      var myCaptionFrameY1 = myCaptionFrame.geometricBounds[0];

      //calculate the offset
      var myOffset = myCaptionFrameY1 - myImageFrameY2; 

      //place the caption at the bottom of the graphic

      myCaptionFrame.geometricBounds = [myImageFrameY2, myCaptionFrame.geometricBounds[1], myCaptionFrame.geometricBounds[2]-myOffset, myCaptionFrame.geometricBounds[3]];

      Should I reference the caption frame in another way? Or is in this case an ungroup requiered before I move the caption frame? How could that be accomplished?