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.
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
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
Copy link to clipboard
Copied
Thank you Manan,
Didn't think it was that easy! 🙂
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 )
Copy link to clipboard
Copied
Thank you for that helpful explanation Uwe!