Usually, the "textframes" array of an object points to the textframes contained in that object. Therefore, if you ask something with textframes what the parent is of "textframes", you will get that same object again.
In this case you are getting an error because there are (apparently) no text frames inside the anchored object.
To try out stuff like this you can use the "constructor.name" construction:
with the anchored object selected results "Character". That cannot ever be a part of a page, so you have to get up another level:
will tell you it's a Story. Now that's obviously wrong, because a story can run over several pages. Looking into the Object Model, you will see a character also has a property "parentTextFrames" (described as "The text frames that contain the Character. Can return: Array of TextFrames or TextPaths."). Checking with
now returns the text frame of the story where the actual character -- in this case the Anchored object -- is located in.
For simple documents and scripts, you are done here: the parent of a text frame is the page. If this frame in turn could be anchored inside something else, or the anchored object could be inside a table or something like that, or the objects could be on the pasteboard or on a master page, you'll need additional checks.
yes, displayed only "character", but not page number.Then how to get page number.
Try this code,
Use below code:
if ((app.selection.parentTextFrames.parent.constructor.name) == "Character" && app.selection.parentTextFrames.parent.parent.constructor.name == "Story")
Thanks, ramkumar for your reply.