• Global community
    • Language:
      • Deutsch
      • English
      • EspaƱol
      • FranƧais
      • PortuguĆŖs
  • ę—„ęœ¬čŖžć‚³ćƒŸćƒ„ćƒ‹ćƒ†ć‚£
    Dedicated community for Japanese speakers
  • ķ•œźµ­ ģ»¤ė®¤ė‹ˆķ‹°
    Dedicated community for Korean speakers
Exit
0

Problem with oFrame.NextAFrame

Community Expert ,
May 27, 2019 May 27, 2019

Copy link to clipboard

Copied

Dear friends,

This time I wanted just to go through the anchored frames in a document. The document contains at least 25 of them and all have a User String.

I fail  with getting the next object with property NextAFrame.

The following script just lists the current frame from which I start. I list also H in case ther is no User String.

// TraverseFrames.jsx  2019-05-27

#target framemaker

TraverseFrames();

function TraverseFrames() {

var oFrame, oObject, oDoc=app.ActiveDoc;

$.bp(true);

  oObject = oDoc.FirstSelectedGraphicInDoc;

  if (!oObject.ObjectValid()) {

    $.writeln ("No or invalid object is selected.");

    return;

  }

  if (oObject.constructor.name == "AFrame") {

    oFrame = oObject;

    $.writeln(oFrame.UserString + " H= " + oFrame.Height);

    oFrame = oFrame.NextAFrame;

    while (oFrame.ObjectValid()) {

      $.writeln(oFrame.UserString + " H= " + oFrame.Height);

      oFrame = oFrame.NextAFrame;

    }

  }

} //---  end TraverseFrames

Where is the knot in my brain?

Klaus

TOPICS
Scripting

Views

1.6K

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

Advocate , May 27, 2019 May 27, 2019

Hello Klaus,

You are starting from a selected graphic object. I suspect the NextAFrame property for that object is not set at all, unless you have multiple graphic objects selected at the same time.

As you are trying to get to all AFrame objects in the document, you might want to start with oDoc.FirstGraphicInDoc and then cycle through all Graphic objects to see if they are an AFrame - for which you can then push the text to your file.

Linked lists are not totally obvious in FM as there are often

...

Votes

Translate

Translate
Advocate ,
May 27, 2019 May 27, 2019

Copy link to clipboard

Copied

Hello Klaus,

You are starting from a selected graphic object. I suspect the NextAFrame property for that object is not set at all, unless you have multiple graphic objects selected at the same time.

As you are trying to get to all AFrame objects in the document, you might want to start with oDoc.FirstGraphicInDoc and then cycle through all Graphic objects to see if they are an AFrame - for which you can then push the text to your file.

Linked lists are not totally obvious in FM as there are often placeholders which exist but might not be valid at all. I always use ObjectValid( ) even if I know it cannot be invalid. Just to make sure. And I always put the jump to the next object outside the if statement, so that I am never ending up in an endless loop.

var oDoc = app.ActiveDoc;

var oGraphic = oDoc.FirstGraphicInDoc;

while( oGraphic.ObjectValid( ) )

{

     if( oGraphic.constructor.name == "AFrame" )

     {

          // run your code here

     }

     oGraphic = oGraphic.NextGraphicInDoc;

}

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
Engaged ,
May 27, 2019 May 27, 2019

Copy link to clipboard

Copied

        var graphic = .doc.FirstGraphicInDoc;

        while (graphic.ObjectValid())

        {

            if (graphic.type != Constants.FO_AFrame)

            {

                graphic = graphic.NextGraphicInDoc;

                continue ;

            }

            //do something here

            graphic = grpahic.NextGraphicInDoc

        }

Hi Klaus,

this is how I traverse all anchored frame. Get First and then Next graphics and check if it's an Anchored Frame by type.

Hope this helps

Markus

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
Engaged ,
May 27, 2019 May 27, 2019

Copy link to clipboard

Copied

Jang, Klaus,

interesting approach:

oGraphic.constructor.name

Haven't done this like this before. Thanks for this.

Markus

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
Community Expert ,
May 27, 2019 May 27, 2019

Copy link to clipboard

Copied

Thank you Jang for the immediate response,

I knew to traverse the whole set of anchored frames by this method - and did so in other circumstances. But this time I want to start at the currently selected object...

Hence my idea is to use the proposed method to find the currently selected object by means of the ID and continue from there with the NextGraphicInDoc method:

// TraverseFrames.jsx  2019-05-27

#target framemaker

TraverseFrames();

function TraverseFrames() {

var oFrame, oObject, oDoc=app.ActiveDoc, thisID, oFLow, oTextFrame, oGraphic ;

$.bp(true);

  oObject = oDoc.FirstSelectedGraphicInDoc;

  if (!oObject.ObjectValid()) {

    $.writeln ("No or invalid object is selected.");

    return;

  }

  if (oObject.constructor.name == "AFrame") {

    oFrame = oObject;

    thisID = oFrame.id;

    $.writeln(" ID= " + oFrame.id);

  

    oGraphic = oDoc.FirstGraphicInDoc;

    while (oGraphic.ObjectValid( ) ) {

      if (oGraphic.constructor.name == "AFrame" ) {

        $.writeln(" id= " + oGraphic.id);

        if (oGraphic.id == thisID) {break;}

      }

      oGraphic = oGraphic.NextGraphicInDoc;

    }

    $.writeln ("--- current frame found ----");

    oGraphic = oGraphic.NextGraphicInDoc;

    while (oGraphic.ObjectValid()) {

      if (oGraphic.constructor.name == "AFrame" ) {

        $.writeln(oGraphic.UserString + " ID= " + oGraphic.id);

      }

      oGraphic = oGraphic.NextGraphicInDoc;

    }

  }

} //---  end TraverseFrames

This works as expected

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
Advocate ,
May 27, 2019 May 27, 2019

Copy link to clipboard

Copied

LATEST

You could also try to use the NextGraphicInDoc property from the FirstSelectedGraphicInDoc object, instead of the NextAFrame. It is possible that the objects are linked via NextGraphicInDoc regardless of being selected or not. Possibly the NextAFrame is not even used at all.

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