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

find anchored object in textframe

Engaged ,
Sep 16, 2021 Sep 16, 2021

Copy link to clipboard

Copied

Hi.

 

I have a document with a lot of text frames. Some of them contain an anchored object and some do not. How can I find an anchored object in a text frame and store it in a variable? It (the anchored item) can also be a text frame, a graphic element or a group of different elements.

 

Bildschirmfoto 2021-09-16 um 16.24.50.png

TOPICS
How to , Scripting

Views

708

Translate

Translate

Report

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 , Sep 16, 2021 Sep 16, 2021

The following code should work, run it with the textframe selected in which you want to get the anchored frames

var tf = app.selection[0] //If this is your selection
var anchoredFrames = tf.pageItems
alert("The selected textframe has " + anchoredFrames.length + " anchored objects")

-Manan

Votes

Translate

Translate
Community Expert ,
Sep 16, 2021 Sep 16, 2021

Copy link to clipboard

Copied

The following code should work, run it with the textframe selected in which you want to get the anchored frames

var tf = app.selection[0] //If this is your selection
var anchoredFrames = tf.pageItems
alert("The selected textframe has " + anchoredFrames.length + " anchored objects")

-Manan

Votes

Translate

Translate

Report

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
Engaged ,
Sep 21, 2021 Sep 21, 2021

Copy link to clipboard

Copied

LATEST

Thank you Manan,

Didn't think it was that easy! 🙂

Votes

Translate

Translate

Report

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 ,
Sep 16, 2021 Sep 16, 2021

Copy link to clipboard

Copied

To rephrase what Manan expressed in code:

 

Anchored objects are page items that belong to text.

The parent of an anchored object is a text object; a character.

 

So you can get an array of anchored objects of a story with:

myStory.pageItems.everyItem().getElements()

Or from selected text:

app.selection[0].pageItems.everyItem().getElements()

 

If you want to loop the allPageItems array of the document you could ask every entry of that array if its parent is a character. If that's true for an individual page item you discovered an anchored object and you can store it in a different array if you like.

 

Regards,
Uwe Laubender

( ACP )

Votes

Translate

Translate

Report

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
Engaged ,
Sep 20, 2021 Sep 20, 2021

Copy link to clipboard

Copied

Thank you for that helpful explanation Uwe!

Votes

Translate

Translate

Report

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