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

[JS] Check if character is an inline frame

Enthusiast ,
Feb 11, 2008 Feb 11, 2008

Copy link to clipboard

Copied

How would if check if a character is an inline frame?

if (myFindsB[0].parent.characters[myIndex +1].contents == inlineFrame)
TOPICS
Scripting

Views

2.8K

Translate

Translate

Report

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

Copy link to clipboard

Copied

Ok, so then shouldn't this return the same thing?

myFindsB[0].parent.characters[myIndex]

Votes

Translate

Translate

Report

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

Copy link to clipboard

Copied

No, but
>myFindsB[0].parent.characters[myIndex].index

should.

Votes

Translate

Translate

Report

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

Copy link to clipboard

Copied

Ah, that's there my mistake was. I forgot to add index at the end.

Votes

Translate

Translate

Report

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

Copy link to clipboard

Copied

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.

Votes

Translate

Translate

Report

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

Copy link to clipboard

Copied

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)

Votes

Translate

Translate

Report

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

Copy link to clipboard

Copied

Fred,

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

if(myFindsB[0].parentTextFrames[0].parent instanceof Character)

Votes

Translate

Translate

Report

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

Copy link to clipboard

Copied

Maybe. But could you remind us what exactly you're trying to accomplish?

Votes

Translate

Translate

Report

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

Copy link to clipboard

Copied

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.

Votes

Translate

Translate

Report

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

Copy link to clipboard

Copied

BTW, when I say select an inline frame, I mean with the type tool, as
opposed to the selection tool.

Votes

Translate

Translate

Report

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

Copy link to clipboard

Copied

Thanks, X and Harbs, for the explanation.

Votes

Translate

Translate

Report

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

Copy link to clipboard

Copied

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

Votes

Translate

Translate

Report

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

Copy link to clipboard

Copied

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.

Votes

Translate

Translate

Report

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

Copy link to clipboard

Copied

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

Votes

Translate

Translate

Report

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

Copy link to clipboard

Copied

Can't you just check the length of the character's page items collection?

Dave

Votes

Translate

Translate

Report

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

Copy link to clipboard

Copied

Hey Dave, you're right!

A regular character has 0 pageItems and an anchored frame character has 1. Very good!

Votes

Translate

Translate

Report

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

Copy link to clipboard

Copied

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.

Votes

Translate

Translate

Report

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

Copy link to clipboard

Copied

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

Votes

Translate

Translate

Report

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

Copy link to clipboard

Copied

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

Votes

Translate

Translate

Report

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