Copy link to clipboard
Copied
Hello. I'm working on a publication that has hundrds of anchored images within the text. I need to release them from anchoring and place them where they are but not anchored. I found some scripts that worked on earlier versions of InDesign, but I'm using v18.2.1 on a Mac. I'm not sure if the structure of InDesign changed or I'm setting up the script incorrectly because I keep getting a syntax error when I try to run the scripts (I'm not a scripter so I might be using the scripts incorrectly).
Anu suggestions?
Thanks,
Lloyd
Hi @Lloydie J, I wrote this just now and it seems to work okay (Indesign 18.3 MacOS).
- Mark
/**
* Release All Anchored Objects.
* @discussion https://community.adobe.com/t5/indesign-discussions/release-all-anchored-objects-at-once/m-p/13797933#M527123
*/
function main() {
var doc = app.activeDocument,
items = doc.allPageItems,
counter = 0,
oversetCounter = 0;
for (var i = items.length - 1; i >= 0; i--) {
if (
items[i].parent.construc...
Copy link to clipboard
Copied
Try putting the script into a subfolder of the Scripts folder named "Version 17.0 Scripts" (without the quote marks, but it is case sensitive).
Copy link to clipboard
Copied
Hi @Lloydie J, I wrote this just now and it seems to work okay (Indesign 18.3 MacOS).
- Mark
/**
* Release All Anchored Objects.
* @discussion https://community.adobe.com/t5/indesign-discussions/release-all-anchored-objects-at-once/m-p/13797933#M527123
*/
function main() {
var doc = app.activeDocument,
items = doc.allPageItems,
counter = 0,
oversetCounter = 0;
for (var i = items.length - 1; i >= 0; i--) {
if (
items[i].parent.constructor.name == 'Character'
&& items[i].hasOwnProperty('anchoredObjectSettings')
) {
if (items[i].parent.parentTextFrames.length > 0) {
items[i].anchoredObjectSettings.anchoredPosition = AnchorPosition.ANCHORED;
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');
Edit 2023-05-19: added check for overset text (thanks @Laubender!) and also a counter, because I like to know what happened when I run a script. 🙂
Copy link to clipboard
Copied
Perfect. It took me a few minutes but I got this to work. I appreciate your help!
Copy link to clipboard
Copied
Thank you so much! Only your script helped me to save my problem with frame and anchored objects!
Copy link to clipboard
Copied
@ m1b
Copy link to clipboard
Copied
Thank you so much! Only your script helped me to save my problem with frame and anchored objects!
Copy link to clipboard
Copied
You're very welcome. I'm glad it helped!
Copy link to clipboard
Copied
Hi @Lloydie J ,
you said:
"I'm not sure if the structure of InDesign changed or I'm setting up the script incorrectly because I keep getting a syntax error when I try to run the scripts (I'm not a scripter so I might be using the scripts incorrectly)."
It's highly unlikely that the failure of the script has to do with a change in that particular version of InDesign.
The document object model's methods and properties that have to do with releasing anchored objects did not change since InDesign CS5.5 version 7.5 that was released about 12 years ago. For example, the parent of an anchored object is still a character. Still one could gather all anchored objects of a particular story with story.allPageItems.
What could be different is the situation the script is facing inside a particular document.
That the script is not written to handle a particular situation. A case the author of the script did not think about.
Perhaps there is overset text that contains anchored objects. Maybe other cases as well...
FWIW: Releasing anchored objects could be done in two or more ways.
[1] Use method releaseAnchoredObject(). A method that is not working with inline or above line anchored objects. Hm. But in both cases no error is thrown; it just does not work, the anchored object will still be anchored after running the code. Even if you try use the method of on anchored objects, not inline or above line anchored, inside overset text, no error is thrown when the method fails.
[2] Duplicate the anchored object with method duplicate(); remove the anchored original one and work on with the duplicate. However, trying to duplicate an anchored object that is inside overset text will literally crash InDesign without any error message.
Without seeing the script's code plus having the document at hand I cannot tell what's going wrong.
Regards,
Uwe Laubender
( Adobe Community Expert )
Copy link to clipboard
Copied
I said: "Still one could gather all anchored objects of a particular story with story.allPageItems."
Ok. That was a bit sloppy. Still one has to check what the parent of every object is in that resulting array of items.
Regards,
Uwe Laubender
( Adobe Community Expert )
Copy link to clipboard
Copied
Excellent point Uwe! A quick script will not handle all the possible cases. I have added a check for anchored objects in overset text now, but there are many other possible ways to stymie the script, depending on the document.
@Lloydie J if you try it out, and get errors, please try it again on a sample document with a similar set-up and see if you can reproduce the errors. If the error still appears then great! just post the sample document and I (or anybody one the forum here) can test and potentially fix. As Uwe notes, posting sample document and code is the fastest way of getting answers to script errors.
- Mark
Find more inspiration, events, and resources on the new Adobe Community
Explore Now