Skip navigation
Currently Being Moderated

Deleting anchored frames

Feb 7, 2012 3:22 AM

Hello all,


What happens with a linked list of objects when I use the Delete method on one of these objects ? The FrameMaker Scripting Guide does not say much about this, nor does the FDK reference guide. I have tried the following but it does not work as I expected:


doc = app.ActiveDoc;

theGraph = doc.FirstGraphicInDoc;

n = 0;


while ( theGraph.ObjectValid() ) {

          tobedeleted = false;

          if ( == "AFrame" ) {

    theObject = theGraph.FirstGraphicInFrame;

    if ( theObject.ObjectValid() )

      if ( == "TextFrame" )

        tobedeleted = true;


    if ( tobedeleted ) {

      nextGraph = theGraph.NextGraphicInDoc;



      theGraph = nextGraph;

    } else

        theGraph = theGraph.NextGraphicInDoc;


alert ( n );


The document has 18 of the specified anchored frames (with embedded text frames), but the above code only deletes 5. If I just walk through the list and skip deleting the objects, the count goes up to 18, as expected. So there must be some crazy side effect of deleting an object from a linked list. But what exactly ?


How can I walk through a linked list and delete some objects from them without disrupting the linked list ?



  • Currently Being Moderated
    Feb 7, 2012 4:51 AM   in reply to 4everJang

    Hi Jang,


    You might find this tutorial useful:



    The code is FrameScript, but the concepts are the same in ExtendScript and the FDK. Please let me know if you have any questions or comments.



    Mark as:
  • Currently Being Moderated
    Feb 7, 2012 6:21 AM   in reply to 4everJang

    I'll have to take some time to try your code and try to understand what is going on. In the meantime, another approach is to loop through the anchored frames save the objects that you want to delete in an array. Then, you can loop through the array and delete each object. It may be a bit less efficient, but each loop can be very simple.


    var doc = app.ActiveDoc;
    var graphic = doc.FirstGraphicInDoc;
    var textFrame;
    var toDelete = [ ];


    while(graphic.ObjectValid()) {
      if ( === "AFrame") {
        textFrame = graphic.FirstGraphicInFrame;
        if (textFrame.ObjectValid()) {
          if ( === "TextFrame") {
            toDelete.push(graphic); // Store the frame in the array.
      graphic = graphic.NextGraphicInDoc;


    // Loop through the array of anchored frames and delete each one.

    for (var i = 0; i < toDelete.length; i += 1) {

    Mark as:
  • Currently Being Moderated
    Feb 8, 2012 8:53 AM   in reply to 4everJang

    Hi Jang,


    I orginally developed this for deleting certain elements in a structured document, since these are in a tree and not a linked list and this is the only way to do it reliably.



    Mark as:
  • Currently Being Moderated
    Feb 8, 2012 11:30 AM   in reply to 4everJang

    I agree, FrameSLT is excellent. I am sure you have seen my blog post on FrameSLT:




    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