Skip to main content
Amr.Hamdy
Known Participant
August 18, 2015
Answered

Releasing All Anchor objects/text frames

  • August 18, 2015
  • 3 replies
  • 6353 views

Dear All,

This is my 1st question on AC (Adobe Community), so i will explain what i need here in details and excuse me about my few or even none Experienced in Coding specially in Javascript.

I have a book with many INDD files, these files has a lot of images and objects and text frames are anchored to main text box.

i was searched on AC for way to release all my anchored object and text frames from main text frame. so i found script way.

i found one its name "ReleaseAnyAnchor" and created by "Dave Saunders" to release anchored object (Graphic/text/else) But one by one. and this will take too much time from me to release all the objects on the book. (the code of the Script is below)

//DESCRIPTION: Release Inline & Anchored Items

//Written by Dave Saunders, released on indesignsecrets.com

(function() {

  if (app.documents.length > 0 && // must be a document open

  app.selection.length == 1 && // selection must be of single item

  app.selection[0].parent instanceof Character) { // selection must be anchored

  if (parseFloat(app.version) < 6) {

  releaseMe(app.selection[0]);

  } else {

  app.doScript(releaseMe, undefined, app.selection[0], UndoModes.entireScript, "Release Any Anchor");

  }

  } else {

  alert("Please select an inline item.");

  }

  function releaseMe(myPI) {

  var yePage = findPage(myPI);

  var startBounds = myPI.geometricBounds;

  myPI.anchoredObjectSettings.anchoredPosition = AnchorPosition.anchored;

  myPI.anchoredObjectSettings.releaseAnchoredObject();

  if (yePage != null) {

  myPI.move(yePage);

  }

  myPI.move([startBounds[1], startBounds[0]]);

  }

  function findPage(theObj) {

  if (theObj.hasOwnProperty("baseline")) {

  theObj = theObj.parentTextFrames[0];

  }

  while (theObj != null) {

  if (theObj.hasOwnProperty("parentPage")) return theObj.parentPage;

  var whatIsIt = theObj.constructor;

  switch (whatIsIt) {

  case Page : return theObj;

  case Character : theObj = theObj.parentTextFrames[0]; break;

  case Cell : theObj = theObj.insertionPoints[0].parentTextFrames[0]; break;

  case Note : ; case Footnote : theObj = theObj.storyOffset; break;

  case Application : return null;

  }

  if (theObj == null) return null;

  theObj = theObj.parent;

  }

  return theObj

  } // end findPage

}());


also i found another script that release all the graphics objects but not the Text frame objects. (i get it from AC but i don't remember exactly from where.)


if(app.documents.length!=0) {

    var ad = app.activeDocument;

    var pgit = ad.pageItems;

    var pgitlg = pgit.length;

    var objprocessed = 0;

    if(pgitlg !=0)

    {

        for(i=0; i<pgitlg; i++)

        {

            if(pgit.getElements()[0].constructor.name == "TextFrame")

            {

                var tfg = pgit.allGraphics;

                var tfglg = tfg.length;

                for(j=0; j<tfglg; j++)

                {

                    var rec = tfg.parent;

                    rec.anchoredObjectSettings.releaseAnchoredObject();

                }

            }

        }

    }

}


all the codes are working fine for me, but i need to try to merge or make a new code [as i mentioned that i don't have experiences in JS so i don't know how to compile a new code that make 2 steps of the 2 codes.]


my Request is, Could you please help me to make this new code, or merge them or compile a new code in new file.


i saw this topic Releasing Anchored objects‌ and want to make a new script.


Please try to help me ASAP as i need this script to release all my anchored object to start work on the file.


I need the code to work on any version of INDESIGN.


Thanks guys, waiting you.


Amr

Correct answer Peter Kahrel

Aha. So you need to test if an inline is an anchor. If it is, use .releaseAnchoredObject(), if it is not, then the easiest is to make it into an anchor and release it:

if (pageItems.parent instanceof Character) {

    if (pageItems.anchoredObjectSettings.anchoredPosition !== AnchorPosition.ANCHORED) {

        pageItems.anchoredObjectSettings.anchoredPosition = AnchorPosition.ANCHORED;

    }

    pageItems.anchoredObjectSettings.releaseAnchoredObject();

}

This does work but I don't know if the results are what you're after.

Peter

3 replies

Participating Frequently
May 3, 2016

Thank you so much, Peter. Script works a treat!

Marie

carolynRSC
Participant
August 30, 2017

I want to say that it's easier to cut the object and paste it back in.

Carolyn Sims

Loic.Aigon
Legend
August 31, 2017

Hi carolynRSC,

Imagine you have dozens of anchored objects, is it still easier to do it manually that in one pass with a script ?

Peter Kahrel
Community Expert
Community Expert
August 18, 2015

Try this:

if (app.documents.length > 0) {

    pageItems = app.documents[0].allPageItems;

    for (i = pageItems.length-1; i >= 0; i--) {

        if (pageItems.parent instanceof Character) {

            pageItems.anchoredObjectSettings.releaseAnchoredObject();

        }

    }

}

Peter

Amr.Hamdy
Amr.HamdyAuthor
Known Participant
August 19, 2015

Dear @pkahrel

i want thank you for this great Code, i test is and the results was as the 1st code i posted.

the main function i need to adjust in my codes ... that i want to release the Text Frams/Graphical/images that anchored in the Inline Mode, not to be on custom mode.

if you can help me in this. i will be very thankful.

i need to make the 2nd code i posted working with search and apply function in all the Open INDD file.


Thanks,

Amr

Peter Kahrel
Community Expert
Peter KahrelCommunity ExpertCorrect answer
Community Expert
August 19, 2015

Aha. So you need to test if an inline is an anchor. If it is, use .releaseAnchoredObject(), if it is not, then the easiest is to make it into an anchor and release it:

if (pageItems.parent instanceof Character) {

    if (pageItems.anchoredObjectSettings.anchoredPosition !== AnchorPosition.ANCHORED) {

        pageItems.anchoredObjectSettings.anchoredPosition = AnchorPosition.ANCHORED;

    }

    pageItems.anchoredObjectSettings.releaseAnchoredObject();

}

This does work but I don't know if the results are what you're after.

Peter

Peter Spier
Community Expert
Community Expert
August 18, 2015

Try this one from Jongware:

//by jongware

n = app.selection[0].textFrames.length;

while (n >= 0)

{

     try {

          app.selection[0].textFrames.anchoredObjectSettings.releaseAnchoredObject();

     } catch(_) {}

     n--;

}

Amr.Hamdy
Amr.HamdyAuthor
Known Participant
August 18, 2015

hello @Peter Spier

after test it by Copy & Paste it in EST,

nothing happened when i Select the text frame or graphical object.

i need to make a new code that search in all the open INDD file (as in 1st code.) and release all Kind of anchored Object in the file.

Graphical, images, text frame.

the 1st code is release the objects that in custom mode of anchor, i need to add the text frame object to be released too.

Peter Spier
Community Expert
Community Expert
August 18, 2015

OK. I've moved this over into the scripting forum where you'll get better help.