• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

How do I loop through AFrames?

Participant ,
Apr 21, 2012 Apr 21, 2012

Copy link to clipboard

Copied

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;

        }

    }

TOPICS
Scripting

Views

1.8K

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Community Expert , Apr 21, 2012 Apr 21, 2012

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

...

Votes

Translate

Translate
Community Expert ,
Apr 21, 2012 Apr 21, 2012

Copy link to clipboard

Copied

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.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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Apr 21, 2012 Apr 21, 2012

Copy link to clipboard

Copied

LATEST

Rick,

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.

Joe

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines