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

This is confusing again: "alert(sel);" is correct, so why is the second 'alert' wrong?

Guide ,
Sep 18, 2025 Sep 18, 2025

When I select an image within the text, I want to obtain the width of the textFrame.
The result throws an error.

alert(sel); is right.

 

alert(sel.geometricBounds[3]); Error popup: Object is invalid

Does textFrame not have a geometricBounds property?

dublove_0-1758215401729.jpegdublove_1-1758215424826.jpeg

 

 

item = app.activeDocument.selection[0];
var doc = app.activeDocument;
var sel = item.parent.parent.textFrames[0]
alert(sel);

alert(sel.geometricBounds[3]);

 

TOPICS
How to , Scripting
95
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

People's Champ , Sep 18, 2025 Sep 18, 2025

Instead of app.activeDocument you can just use the shortcut property document.

Next, you've got an anchored object selected. Its parent is a character. And its parent is a story.

You access all the text frames that are part of a story with the property textContainers which returns an array. (story.textFrames will return any text frames that are anchored to the first insertion point of that story, basically useless.) But this won't really help you, because you may not know which frame the anchored

...
Translate
People's Champ ,
Sep 18, 2025 Sep 18, 2025

Instead of app.activeDocument you can just use the shortcut property document.

Next, you've got an anchored object selected. Its parent is a character. And its parent is a story.

You access all the text frames that are part of a story with the property textContainers which returns an array. (story.textFrames will return any text frames that are anchored to the first insertion point of that story, basically useless.) But this won't really help you, because you may not know which frame the anchored object is in.

Instead, to get the textFrame that a character is in, go directly, using the parentTextFrames property: document.selection[0].parent.parentTextFrames[0].geometricBounds[3]

 

 

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
Guide ,
Sep 18, 2025 Sep 18, 2025
LATEST

This problem again.
Great.
Thanks.

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