Skip navigation
Currently Being Moderated

How do I loop through AFrames?

Apr 21, 2012 7:22 AM

I feel dumb asking this but I really think the code I have should work. All I want to do is loop through all the aframes in a document. To do this, I assign the first Aframe to a variabe named vAFrame. Then, I created a while loop where the test is vAFrame.ObjectValid(). however, the while loop never tests to true even though the data browsers shows that the vAFrame variable contains a valid object AND it supports the ObjectValid() method AND the valid object is an AFrame. I must be missing something really obvious here. Any ideas?

 

main ()

 

function main()

{

    var vDoc=app.ActiveDoc;

    var vFlow=vDoc.MainFlowInDoc;

    var vTextFrame=vFlow.FirstTextFrameInFlow;

    var vAFrame=vTextFrame.FirstAFrame;

    while (vAFrame.ObjectValid())

    {

        vAFrame=vAFrame.NextAFrame;

        }

    }

 
Replies
  • Currently Being Moderated
    Apr 21, 2012 7:43 AM   in reply to jaloren28

    I am heads down on a project so I can't give you much code right now, but I can point you in the right direction. The method you are using only works for a single text frame, so you would also have to include a loop for all of the text frames in the flow. A better approach is to get a list of FrameAnchor items from the main flow of the document. Then you can loop through the text items to process each anchored frame.

     

    // Set a variable for the main flow in the document.

    var flow = doc.MainFlowInDoc;

    // Get a list of the anchored frames in the flow.

    var textItems = flow.GetText(Constants.FTI_FrameAnchor);

    // Loop through the anchored frames.

    for (var i = 0; i < textItems.len; i += 1) {

      var aFrame = textItems[i].obj;

      // Do something with the anchored frame here.

    }

     

    Note that this will only get anchored frames in the main flow itself; it will skip anchored frames that are inside table cells or nested in other anchored frames. Please let me know if you have any questions or comments.

     

    Rick Quatro

     
    |
    Mark as:

More Like This

  • Retrieving data ...

Bookmarked By (0)

Answers + Points = Status

  • 10 points awarded for Correct Answers
  • 5 points awarded for Helpful Answers
  • 10,000+ points
  • 1,001-10,000 points
  • 501-1,000 points
  • 5-500 points