Skip to main content
4everJang
Legend
January 30, 2012
Answered

How to get to text in an anchored frame

  • January 30, 2012
  • 1 reply
  • 3259 views

Hello,

I am working on unstructured FrameMaker files, in preparation of comverting them into structured documents. My customer has placed lots of authoring notes in the sidehead of their documents. They are inserted as text frames inside anchored frames. I am trying to retrieve the text from the anchored frames so that I can move it into a new paragraph where it will be picked up by the conversion process.

Browsing through the ExtendScript reference for FrameMaker I find an AFrame object, but it only lists elements and properties pointing to graphics that may be entered into this frame, not text ranges. In the Data Browser I find InvalidObject for the FirstGraphicInFrame and no pointers to any kind of TextFrame.

Can anyone tell me how to get a handle on the text frame in those anchored frames ?

Thanks in advance

Jang

This topic has been closed for replies.
Correct answer 4everJang

Hi Jang,

OK, here is what I tried. I select an anchored frame that has a text frame in it and run this code:

var doc = app.ActiveDoc;
var aframe = doc.FirstSelectedGraphicInDoc;

var graphic = aframe.FirstGraphicInFrame;
alert(graphic.constructor.name);

The alert displays "TextFrame" like I would expect. You can also do this to display the Name propety of the FirstPgf property of the text frame:

var doc = app.ActiveDoc;
var aframe = doc.FirstSelectedGraphicInDoc;

var graphic = aframe.FirstGraphicInFrame;
alert(graphic.FirstPgf.Name);

This works for me as well. You should post your code so we can see what might be wrong. Thanks.

Rick


Hello again Rick,

I got it now. I was looking for the wrong type of object. As the anchored frame looks like an anchored frame to me, not like a graphic, I never thought of finding the FirstGraphicInDoc and then treat it like an anchored frame with text frames in it. The FM scripting guide could do with a couple of good examples here and there. I changed the FirstSelectedGraphicInDoc to FirstGraphicInDoc and it finds the objects I was looking for.

Thanks

Jang

1 reply

frameexpert
Community Expert
Community Expert
January 30, 2012

Hi Jang,

You have to loop through the graphic object(s) in the anchored frame and test each graphic to see if it is a text frame. For example, if aframe is your anchored frame object:

// Set a variable for the first graphic in the anchored frame.

var graphic = aframe.FirstGraphicInFrame;

// Loop through the graphics in the anchored frame.

while (graphic.ObjectValid()) {

  // Test to see if the graphic is a text frame.

  if (graphic.constructor.name === "TextFrame") {

    // Do something with the text frame here.

  }

  // Move to the next graphic in the anchored frame.

  graphic = graphic.NextGraphicInFrame;

}

Please let me know if you have any questions or comments.

Rick Quatro

4everJang
4everJangAuthor
Legend
January 30, 2012

Hi Rick,

The FirstGraphicInFrame property of my anchored frame shows InvalidObject in the data browser. There is no linked list of graphic objects that I can walk through to find a text frame. I am using FM 10.0.0.388

Jang

frameexpert
Community Expert
Community Expert
January 30, 2012

Hi Jang,

OK, here is what I tried. I select an anchored frame that has a text frame in it and run this code:

var doc = app.ActiveDoc;
var aframe = doc.FirstSelectedGraphicInDoc;

var graphic = aframe.FirstGraphicInFrame;
alert(graphic.constructor.name);

The alert displays "TextFrame" like I would expect. You can also do this to display the Name propety of the FirstPgf property of the text frame:

var doc = app.ActiveDoc;
var aframe = doc.FirstSelectedGraphicInDoc;

var graphic = aframe.FirstGraphicInFrame;
alert(graphic.FirstPgf.Name);

This works for me as well. You should post your code so we can see what might be wrong. Thanks.

Rick