Copy link to clipboard
Copied
In javascript, how to get page number of anchored textbox.
if i gave "textframes[0].parent" means it shows an error.
Thanks
Use below code:
if ((app.selection[0].parentTextFrames[0].parent.constructor.name) == "Character" && app.selection[0].parentTextFrames[0].parent.parent.constructor.name == "Story")
{
alert(app.selection[0].parentTextFrames[0].parent.parentTextFrames[0].parent.name)
}
Copy link to clipboard
Copied
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[0]", 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:
alert (app.selection[0].parent.constructor.name);
with the anchored object selected results "Character". That cannot ever be a part of a page, so you have to get up another level:
alert (app.selection[0].parent.parent.constructor.name);
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
alert (app.selection[0].parent.parentTextFrames[0].constructor.name);
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.
Copy link to clipboard
Copied
yes, displayed only "character", but not page number.Then how to get page number.
alert (app.selection[0].parentTextFrames[0].parent.constructor.name);
Copy link to clipboard
Copied
Try this code,
alert (app.selection[0].parent.parentTextFrames[0].parent.name);
Copy link to clipboard
Copied
Use below code:
if ((app.selection[0].parentTextFrames[0].parent.constructor.name) == "Character" && app.selection[0].parentTextFrames[0].parent.parent.constructor.name == "Story")
{
alert(app.selection[0].parentTextFrames[0].parent.parentTextFrames[0].parent.name)
}
Copy link to clipboard
Copied
Copy link to clipboard
Copied
Thanks, ramkumar for your reply.
Copy link to clipboard
Copied
That looks like one of Dave's...
Find Page has been discussed on the forums many times...
Here's one discussion:
http://forums.adobe.com/message/1109753#1109753
and here's an older one:
http://forums.adobe.com/message/1110815#1110815
I think most of the original discussions are gone already...
Harbs
Find more inspiration, events, and resources on the new Adobe Community
Explore Now