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