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

[JS] Check if character is an inline frame

Enthusiast ,
Feb 11, 2008 Feb 11, 2008
How would if check if a character is an inline frame?

if (myFindsB[0].parent.characters[myIndex +1].contents == inlineFrame)
TOPICS
Scripting
5.4K
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
Enthusiast ,
Feb 12, 2008 Feb 12, 2008
Ok, so then shouldn't this return the same thing?

myFindsB[0].parent.characters[myIndex]
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
Community Expert ,
Feb 12, 2008 Feb 12, 2008
No, but
>myFindsB[0].parent.characters[myIndex].index

should.
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
Enthusiast ,
Feb 12, 2008 Feb 12, 2008
Ah, that's there my mistake was. I forgot to add index at the end.
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
Enthusiast ,
Feb 12, 2008 Feb 12, 2008
Nope it's still not working.

This is never returning true:
if(myFindsB[0].parent.characters[myIndex+1].parentTextFrames[0].parent instanceof Character){

Even when

myFindsB[0].parent.characters[myIndex+1]

Is an inline frame.
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
Enthusiast ,
Feb 12, 2008 Feb 12, 2008
Is it possible there is a difference between inline frames that are part of the text and inline anchored markers?

Because when I select an inline frame and run this script I get object page.

alert(app.selection[0].parentTextFrames[0].parent)
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
LEGEND ,
Feb 12, 2008 Feb 12, 2008
Fred,

I'm a little confused. Shouldn't this be what you want?

if(myFindsB[0].parentTextFrames[0].parent instanceof Character)
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
Community Expert ,
Feb 12, 2008 Feb 12, 2008
Maybe. But could you remind us what exactly you're trying to accomplish?
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
Enthusiast ,
Feb 12, 2008 Feb 12, 2008
Ok, I am finding tags. These tags represent horizontal rules. Here is an
example of a tag: |hrule5|

Now if right after this tag there is an inline frame I only want the
rule to go until the anchored frame. And if there is not an inline frame
I want the rule to be the width of the text frame.

So I would like to test the character right after myFinds (which is an
array of these tags) to see if there is an inline frame, and if it is
get its geometric bounds so I can subtract that from the
parentTextFrame's geometric bounds to get the width of the rule.
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
Enthusiast ,
Feb 12, 2008 Feb 12, 2008
BTW, when I say select an inline frame, I mean with the type tool, as
opposed to the selection tool.
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
Community Expert ,
Feb 12, 2008 Feb 12, 2008
Thanks, X and Harbs, for the explanation.
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
Community Expert ,
Feb 12, 2008 Feb 12, 2008
Fred,

When you've got a handle on something inside an inline it's not so hard to figure out whether or not you're in an inline; that was covered earlier in this thread.

Figuring out whether an object that declares itself to be a character is really that (i.e. its contents is a single letter) or an inline takes some less elegant methods. I know of two. (1) Check the character's unicode value: if it's an inline, unicode value FFFC is returned. Any other unicode values mean it's a real character (or likely, anyway; it could also be a special character I guess). (2) A character with geometricBounds must be an inline; a real character has no geometricBounds, so testing for that will produce an error. The latter test would be something like this:

try
{
app.selection[0].textFrames[0].geometricBounds
alert ("It's an inline.")
}
catch(_)
{
alert ("It's a character")
}

with a character (either a plain one or an inline) selected.

Peter
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
Enthusiast ,
Feb 12, 2008 Feb 12, 2008
Ah, checking for Unicode is a good idea.

Harbs,

Peter hit the problem right on the head in this post. When you've got
the object selected there's no problem, but when you want to check the
character it's treated like any other character.
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
LEGEND ,
Feb 12, 2008 Feb 12, 2008
Fred,

I obviously have no clue what you're trying to accomplish, because I
didn't understand a word of what you just wrote! ;)

Of course it's a character. If the frame's parent is a character, the
frame is either inline or anchored. Why are you checking what kind of
character it is? If you want to determine if it's inline or anchored,
you can find that out with the anchoredObjectSettings.

What am I missing? Either way... I'm glad you worked it out...

Harbs
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
Participant ,
Feb 12, 2008 Feb 12, 2008
Can't you just check the length of the character's page items collection?

Dave
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
Enthusiast ,
Feb 13, 2008 Feb 13, 2008
Hey Dave, you're right!

A regular character has 0 pageItems and an anchored frame character has 1. Very good!
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
Enthusiast ,
Feb 13, 2008 Feb 13, 2008
Harbs,

The problem is that if you select the frame as a character (with the text tool) it's parent is a story just like any other character. There is no way to differentiate between them. But Dave's answer is the best, you can just check the length of the pageItems.
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
LEGEND ,
Feb 13, 2008 Feb 13, 2008
LATEST
Hi Fred.

Of course. I've used Dave's method to find inlines/anchored page items
in text many times before. I just didn't/don't understand why you would
select an inline and then check that you selected it...

Whatever... :)

Harbs
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
Participant ,
Feb 13, 2008 Feb 13, 2008
Here's a script I've been using lately because the catalog I'm working on has anchored objects that are otherwise unselectable:
//DESCRIPTION: Select associated anchored object


if (app.documents.length > 0 &&
app.selection.length == 1 &&
app.selection[0].hasOwnProperty("baseline")) {
selectAnchor(app.selection[0]);
}

function selectAnchor(sel) {
try {
app.select(sel.pageItems[0]);
} catch(e) {}
}
The objects in question consisted of a text frame that itself contained as inline objects one or more groups each made up of text frames. There was no way to click on the top-level anchored object without getting one of the contained objects. This was true whether I tried the pointer or text tools.

So, I banged out the above script, which is nearly relevant to this topic!

Dave
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