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

Find the anchored object in the paragraph

Participant ,
Apr 04, 2019 Apr 04, 2019

Copy link to clipboard

Copied

Hi guys;

I want to find the anchored object (first character) in the paragraphs within the text frame.

If possible, I'll find the anchored object in the table frame only within the text frame.

if (myPara.pageItems[0].getElements()[0].constructor.name == "TextFrame")

(Extend Script Note: Object is invalid )

art.png

TOPICS
Scripting

Views

1.6K

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

correct answers 1 Correct answer

Guide , Apr 04, 2019 Apr 04, 2019

Hi,

Supposing you have created a color called "red", these 2 code lines will colorize in "red" all the paras containing an anchored text frame inside of them!

var myParas = app.activeDocument.stories.everyItem().paragraphs;

for ( var p = 0; p < myParas.length ; p++ ) try { if ( myParas

.textFrames.length > 0 ) myParas

.fillColor = "red"; } catch (e) {}

Best,

Michel, for FRIdNGE

Votes

Translate

Translate
Enthusiast ,
Apr 04, 2019 Apr 04, 2019

Copy link to clipboard

Copied

It looks like you are parsing a list of paragraphs with only one containing an anchored item. Make sure you have an item before trying to get its constructor name. To demonstrate: the following shows an alert for the index of paragraphs having an anchored item.

var thisPara, thisAnc;

var docRef = app.documents[0];

var myCount = docRef.stories[0].paragraphs.count();

for (var i = 0; i < myCount; i++) {

thisPara = docRef.stories[0].paragraphs;

if (thisPara.pageItems.count() > 0) {

    alert ("Anchored Item in paragraph  " + i);

}

}

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 ,
Apr 04, 2019 Apr 04, 2019

Copy link to clipboard

Copied

Thank you @S Hopkins, but; just want to see if there is a text frame in a paragraph.

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
Guide ,
Apr 04, 2019 Apr 04, 2019

Copy link to clipboard

Copied

Hi,

Supposing you have created a color called "red", these 2 code lines will colorize in "red" all the paras containing an anchored text frame inside of them!

var myParas = app.activeDocument.stories.everyItem().paragraphs;

for ( var p = 0; p < myParas.length ; p++ ) try { if ( myParas

.textFrames.length > 0 ) myParas

.fillColor = "red"; } catch (e) {}

Best,

Michel, for FRIdNGE

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 ,
Apr 05, 2019 Apr 05, 2019

Copy link to clipboard

Copied

Hi uniqued_tol ,

I looked at your screenshot.

Hm. There is no anchored object, but only a table. A table is not considered an anchored object.

If you want access to that table and you have identified the text frame ( I stored the text frame in variable myTextFrame below )  it's:

var firstTableInFrame = myTextFrame.tables[0];

If you want to get the special character that constitutes the table in its story then do:

// Text frame selected that holds a table:

var myTextFrame = app.selection[0];

var specialCharacterThatHoldsTheTable =

myTextFrame.tables[0].storyOffset.parentStory.characters[ myTextFrame.tables[0].storyOffset.index ];

storyOffset of a table is the first insertion point of the character that holds the table.

You now could use methods move() or duplicate() on that found character if you want. To move or duplicate the table within it's story or to a different story. Even to a different story in a different document.

Look up the methods for a single character and its necessary parameters:

Adobe InDesign CS6 (8.0) Object Model JS: Character

Regards,
Uwe

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 ,
Apr 05, 2019 Apr 05, 2019

Copy link to clipboard

Copied

LATEST

Hi,

Laubender​ and  @Michel Thank you very much for your comments.

I guess I didn't have my problem right. The table is inside the text frame. that is, an anchored object.

I solved my problem with a little change in Michel's code. I had to check if there was a text frame and a table for my paragraph.

myPara.textFrames.everyItem().tables.length>0

got my job:)

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