Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Release All Anchored Objects at Once

Explorer ,
May 17, 2023 May 17, 2023

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

TOPICS
How to , Scripting
1.2K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Community Expert , May 18, 2023 May 18, 2023

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
...
Translate
Community Expert ,
May 17, 2023 May 17, 2023

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).

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
May 18, 2023 May 18, 2023

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. 🙂

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
May 20, 2023 May 20, 2023

Perfect. It took me a few minutes but I got this to work. I appreciate your help!

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Oct 19, 2024 Oct 19, 2024

Thank you so much! Only your script helped me to save my problem with frame and anchored objects!

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Oct 19, 2024 Oct 19, 2024

@ m1b

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Oct 19, 2024 Oct 19, 2024

@m1b

Thank you so much! Only your script helped me to save my problem with frame and anchored objects!

 
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Oct 19, 2024 Oct 19, 2024
LATEST

You're very welcome. I'm glad it helped!

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
May 18, 2023 May 18, 2023

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 )

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
May 18, 2023 May 18, 2023

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 )

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
May 18, 2023 May 18, 2023

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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines