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 )
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
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);
}
}
Copy link to clipboard
Copied
Thank you @S Hopkins, but; just want to see if there is a text frame in a paragraph.
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
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
Copy link to clipboard
Copied
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:)