2 Replies Latest reply on Apr 21, 2012 9:30 AM by jaloren28

    How do I loop through AFrames?

    jaloren28 Level 2

      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())





        • 1. Re: How do I loop through AFrames?
          frameexpert Level 4

          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

          • 2. Re: How do I loop through AFrames?
            jaloren28 Level 2



            You are phenomenal thanks. My plan is to write a script that will examine all the graphics imported by reference and that are also in an anchored frame. Then, based on settings provided by a user, change the DPI, alignment of the anchor frame etc to something else. In my limited experience with writing scripts for FrameMaker, screwing around with graphics and text seem to be one of the hardest things to do so I am sure I will be back here begging for this forum's help.


            However, you've given me a great start. Thanks.