Copy link to clipboard
Copied
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
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 resu
...Copy link to clipboard
Copied
Try this one from Jongware:
//by jongware
n = app.selection[0].textFrames.length;
while (n >= 0)
{
try {
app.selection[0].textFrames
} catch(_) {}
n--;
}
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
OK. I've moved this over into the scripting forum where you'll get better help.
Copy link to clipboard
Copied
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
Copy link to clipboard
Copied
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
Copy link to clipboard
Copied
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
Copy link to clipboard
Copied
Dear pkahrel,
should i add the last code to the previous one you gave it to me, or this a new code to test it...?
Copy link to clipboard
Copied
Dear pkahrel
I tested the code and it's working for test file.
i will test it on the book now and get back to you with the results.
thanks for helping...
Copy link to clipboard
Copied
I'm also trying to release all INLINE (i.e. not custom) anchored objects throughout a document. As commented above, although Dave Saunders' script 'releaseanyanchor' works, it only releases one object at a time. I would be very grateful for advice as to how to incorporate P Kahrel's solution in order to release all inline anchored objects in a file.
Many thanks
Copy link to clipboard
Copied
This one releases inlines but not custom anchors:
stories = app.documents[0].stories.everyItem().getElements();
for (i = 0; i < stories.length-1; i++) {
inlines = stories.pageItems.everyItem().getElements();
for (j = inlines.length-1; j >= 0; j--) {
if (inlines
.parent instanceof Character && inlines .anchoredObjectSettings.anchoredPosition !== AnchorPosition.ANCHORED) { inlines
.anchoredObjectSettings.anchoredPosition = AnchorPosition.ANCHORED; inlines
.anchoredObjectSettings.releaseAnchoredObject(); }
}
}
Peter
Copy link to clipboard
Copied
thanks for your great reply, working fine now.
Copy link to clipboard
Copied
This still works well for the stubborn nested textFrames. How do I implement removing the empty ones it leaves in it's wake?
I decided to try and use via findGrep primarily so I knew the object I was getting could have anchored object settings, but of course the loop catches this regex multiple times, and leaves behind a husk. Deleting/removing gets rid of the text instead of the holding textframes, which does make sense. Or, would it be better to do a separate loop after to delete empty text frames?
function tFBreakOut2() {
app.findGrepPreferences.findWhat = ".*_.*";
needle = app.activeDocument.findGrep();
whileSafe = 0;
for (var p = 0; p < needle.length; p++) {
var ndl = needle[p];
var ndlSt = ndl.parentTextFrames[0].anchoredObjectSettings;
ndlSt.anchoredPosition = AnchorPosition.ANCHORED;
ndlSt.releaseAnchoredObject();
while (ndl.parent.constructor.name != "Spread") {
hay = ndl.parent;
if (whileSafe = 50) break;
whileSafe++;
}
// hay.remove();
}
}
Copy link to clipboard
Copied
Thank you so much, Peter. Script works a treat!
Marie
Copy link to clipboard
Copied
I want to say that it's easier to cut the object and paste it back in.
Carolyn Sims
Copy link to clipboard
Copied
Hi carolynRSC,
Imagine you have dozens of anchored objects, is it still easier to do it manually that in one pass with a script ? ![]()
Copy link to clipboard
Copied
Hi, if you do have dozens yes the script would be better. Thanks!
Carolyn
Copy link to clipboard
Copied
Hi Carolyn, that's basically a good idea, and doing so _manually_ will most probably bring the expected result. However, if you do this by scripting (app.cut() - app.pasteInPlace()), then you will encounter surprising results in terms of where the object will actually be pasted. Depending of several parameters regarding the various coordinate systems and depending on the document's history the object will appear somewhere but not where you expect it. Moreover, you could run into a performance issue as well.
Hence, the recommendation is: Don't do that, but anchor the object if necessary (inline / above the line) and then release it by scripting.
[ Off topic: The same issue is still persistant in InDesign if you override master page items on a document page - also this places the new page item somewhere under certain conditions. Has been reported x times but not yet fixed. ]
Copy link to clipboard
Copied
Hi @rudiwarttmann , You may have missed that this thread is from 2015. Also Peter's releaseAnchoredObject method should leave the object's XY position unchanged
Copy link to clipboard
Copied
Hi @rob day Thanks for your answer ... however: No, I haven't missed anything. If you have a close look you can see that I'm talking about copy(cut)/paste in place via scripting, which has nothing to do with Peter's solution at all.
And especially the described InDesign "behaviour" (= bug) is still persistent. It's a good example how such things persist for years, if not for decades.
Copy link to clipboard
Copied
I made some modifications to this script a while ago - it wasn't working exactly for me at the time the way I needed - I can't recall what was wrong or what I changed but I did something.
/**
* Release All Anchored Objects.
* (Tested in InDesign 18.3 on MacOS)
*/
function main() {
var doc = app.activeDocument,
items = doc.allPageItems,
counter = 0,
oversetCounter = 0;
for (var i = items.length - 1; i >= 0; i--) {
// Check if the object's parent is a character and it has anchored object settings
if (
items[i].parent.constructor.name === 'Character' &&
items[i].hasOwnProperty('anchoredObjectSettings')
) {
// Only proceed if the anchored object is inside a text frame (i.e. not in overset text)
if (items[i].parent.parentTextFrames.length > 0) {
// Force the object into an anchored state
items[i].anchoredObjectSettings.anchoredPosition = AnchorPosition.ANCHORED;
// Release the anchored object
items[i].anchoredObjectSettings.releaseAnchoredObject();
counter++;
} else {
oversetCounter++;
}
}
}
alert('Released ' + counter + ' anchored objects.' + (oversetCounter > 0 ? ' Skipped ' + oversetCounter + ' overset objects.' : ''));
}
app.doScript(main, ScriptLanguage.JAVASCRIPT, undefined, UndoModes.ENTIRE_SCRIPT, 'Release All Anchored Objects');
Find more inspiration, events, and resources on the new Adobe Community
Explore Now