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

[JS CS5] Accessing an inline frame from an insertion point

Participant ,
Mar 09, 2011 Mar 09, 2011

Given an insertion point, how can I determine if it contains an inline/anchored frame? And if so, how do I reference the inline/anchored frame?

I know how to reference the surrounding paragraph, characters, etc., but can't figure out how to get to the inline/anchored graphic.

I normally would just loop through all the inline graphics in the document, but it this case I need to access the inlines via their insertion points.

TOPICS
Scripting
1.0K
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

LEGEND , Mar 09, 2011 Mar 09, 2011

To reference the inline frame:

prevChar.pageItems[0]

or

nextChar.pageItems[0];

Translate
LEGEND ,
Mar 09, 2011 Mar 09, 2011

An insertion point does not contain anything.

It's always a character which contains an inline...

If you want to get the inline/anchored objects of text, use "text.pageItems" (or text.textFrames, etc.)

HTH,

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 ,
Mar 09, 2011 Mar 09, 2011

Harbs, I appreciate the guidance. I'm missing something here. If I have my cursor between two inline frames...

myDoc.selection[0] returns the insertion point,

But how do I reference the character on either side of the insertion point that contains the inline, and then once I have the character, how do I reference the inline frame?

Sorry I'm so dense!

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 ,
Mar 09, 2011 Mar 09, 2011

var story = app.selection[0].parentStory;

var index = app.selection[0].index;

var prevChar = story.characters.item(index-1);

var nextChar = story.characters.item(index);

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 ,
Mar 09, 2011 Mar 09, 2011

To reference the inline frame:

prevChar.pageItems[0]

or

nextChar.pageItems[0];

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
Advisor ,
Mar 09, 2011 Mar 09, 2011

Or in one line:

//

alert(app.selection[0].parent.characters[app.selection[0].index].pageItems.length || app.selection[0].parent.characters[app.selection[0].index-1].pageItems.length);

//

--

Marijan (tomaxxi)

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 ,
Mar 09, 2011 Mar 09, 2011
LATEST

Thanks so much, Harbs. This is exactly what I needed to get me going. I learned something new today!

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
Advisor ,
Mar 09, 2011 Mar 09, 2011

As far as I know, Insertion point can't hold inline/anchored object, but character does.

If you select text and run this line

alert(app.selection[0].pageItems.length);

it will return number of anchor/inline objects inside selected text.

Another way is to check parent of object. Parent of anchor/inline object is always character.

Example script that copies all anchor/inline objects to new layer: http://bit.ly/aV9WMF

Hope that helps.

--

Marijan (tomaxxi)

http://indisnip.wordpress.com/

http://inditip.wordpress.com/

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