Copy link to clipboard
Copied
If no objects are selected, all text Frames in current document will be processed.
I have two targets:
1. Text paragraphs outside the table.
2. Cells inside the table.
How can I get them?
Like this:
obj.texts[0].appliedParagraphStyle)=parStn;
obj.texts[0].tables.everyItem().cells.everyItem().texts[0].appliedParagraphStyle = bodyParStn;
This is my code above.
It seems that it can only go up to this point: alert(“here”);
There is no response below that.
var myDocument = app.documents.item(0);
var myStory = myDocument.stories;
for (var s = 0; s < myStory.length; s++) {
alert("here");
var what = "^.";
var res = getGrepSearch(what, app.activeDocument);
for (var f = 0; f <res.length; f++) {
var obj = app.selection[f];
...
}
}
Text paragraphs outside the table.
Cells inside the table.
var p = app.activeDocument.stories.everyItem().paragraphs.everyItem().getElements()
var c = app.activeDocument.stories.everyItem().tables.everyItem().cells.everyItem().getElements()
alert("An array of " + c.length + " cells in this document")
alert("An array of " + p.length + " paragraphs in this document not included in tables")
If I select a framework
So there is a selection? If so:
//make sure there is a selection
try {
//the parent of a text frame’s text is a story
var s = app.activeDocument.selection[0].texts[0].parent
//all of the paragraphs in the selection
var p = s.paragraphs.everyItem().getElements()
//all of the cells in the text’s tables
var c = s.tables.everyItem().cells.everyItem().getElements()
alert("An array of " + c.length + " cells in this selection")
alert("An a
Watch out for the difference between an Array and a Collection, they are similar but not the same—allGraphics returns an Array, while pageItems returns a Collection:
//allGraphis is an array not a collection
var g = app.activeDocument.stories.everyItem().allGraphics
//pageItems is a collection not an array and can be converted
//to an array by adding everyItem().getElements()
var pi = app.activeDocument.stories.everyItem().pageItems.everyItem().getElements()
alert("Story 1 has " + g[0].leng
Can I look down to the child?
No—there’s no child property
You can get the object’s properties—this gets the first pageItem’s properties as a text list
var p=app.activeDocument.pageItems[0].properties.toSource();
alert("Properties:\r" + p)
You can get all of the document’s graphics—this is an array not a collection:
var g = app.activeDocument.allGraphics
alert("An array of " + g.length + " graphics")
Copy link to clipboard
Copied
Text paragraphs outside the table.
Cells inside the table.
var p = app.activeDocument.stories.everyItem().paragraphs.everyItem().getElements()
var c = app.activeDocument.stories.everyItem().tables.everyItem().cells.everyItem().getElements()
alert("An array of " + c.length + " cells in this document")
alert("An array of " + p.length + " paragraphs in this document not included in tables")
Copy link to clipboard
Copied
It's better to use variables instead of this method, otherwise it will be too long.
I was thinking about your function yesterday. I now have five scenarios, each with independent code, which is a bit long.
Copy link to clipboard
Copied
I suddenly realized that I chose table and text, and constructor.name is also “Text”.
So how can I distinguish it from pure text?
Copy link to clipboard
Copied
If no objects are selected
In your first post you wrote there is no selection
Copy link to clipboard
Copied
I now use this method to distinguish between them:
f ((
(app.selection[0].constructor.name == “TextColumn”)
|| (app.selection[0].constructor.name == “Text”)
|| (app.selection[0].constructor.name == “TeStyleRangle”))
&& ((app.selection[0].texts[0].tables.length > 0)
|| (app.selection[0].texts[0].Rectangles.length > 0)))
{
selTextTable();
}
Copy link to clipboard
Copied
@dublove said: "… So how can I distinguish it from pure text?"
Hi, in this context a table is "stored" as a special character.
From the context of a found table you can get that special character through its first insertion point, that is expressed by the property storyOffset of a table.
Thus the special character is myTable.parent.characters[ myTable.storyOffset.index ] .
// Table selected:
var myTable = app.selection[0];
// Select the special character that contains the selected table from above:
app.select( myTable.parent.characters[ myTable.storyOffset.index ]);
Regards,
Uwe Laubender
( Adobe Community Expert )
Copy link to clipboard
Copied
Hi Laubender.
I don't think you understand what I mean. This is too complicated.
maybe, is it like this?
Copy link to clipboard
Copied
This is too complicated.
What is making it complicated— in your post title you write there is no selection, but in your last post you have 3 text frames selected. If there is a selection you have to test what it is, which does make it much more complicated.
Copy link to clipboard
Copied
Hi Rob Day.
I tested it.
This works:
var c = app.activeDocument.stories[0].tables.everyItem().cells;
Sorry, I may not have explained it clearly.
What I mean is:
When I select a text box, my goal is to select the entire article (the entire stor
Copy link to clipboard
Copied
When no object is selected:
var t = app.activeDocument.stories.everyItem().tables;
var g = app.activeDocument.stories.everyItem().allGraphics;
alert(t.length);
alert(g.length);
The result of alert(t.length) is correct.
It outputs 3, which is indeed the number of tables.
However, alert(g.length) seems to be incorrect, as there are three graphs.
The output is 2.
Copy link to clipboard
Copied
Watch out for the difference between an Array and a Collection, they are similar but not the same—allGraphics returns an Array, while pageItems returns a Collection:
//allGraphis is an array not a collection
var g = app.activeDocument.stories.everyItem().allGraphics
//pageItems is a collection not an array and can be converted
//to an array by adding everyItem().getElements()
var pi = app.activeDocument.stories.everyItem().pageItems.everyItem().getElements()
alert("Story 1 has " + g[0].length + " graphics")
alert("All document stories have " + pi.length + " page items")
Copy link to clipboard
Copied
Hi rob day.
If I select a framework, what are all the frameworks linked to it called?
Is it called a story?
How to represent paragraphs (p) in a story and cells (c) in a table?
Copy link to clipboard
Copied
If I select a framework
So there is a selection? If so:
//make sure there is a selection
try {
//the parent of a text frame’s text is a story
var s = app.activeDocument.selection[0].texts[0].parent
//all of the paragraphs in the selection
var p = s.paragraphs.everyItem().getElements()
//all of the cells in the text’s tables
var c = s.tables.everyItem().cells.everyItem().getElements()
alert("An array of " + c.length + " cells in this selection")
alert("An array of " + p.length + " paragraphs in this selection not included in tables")
}catch(e) {
alert(e)
}
Copy link to clipboard
Copied
When selecting a frame, point to the entire article.
I still used yours, as parent can accurately lock the relationship.
Mine sometimes misleads to other unrelated affected areas.
Copy link to clipboard
Copied
Also, you can get the pageItem’s graphics, which is a Collection:
var g = app.activeDocument.stories.everyItem().pageItems.everyItem().graphics.everyItem().getElements()
alert(g.length)
Copy link to clipboard
Copied
Hi rob day.
Thank you very much.
I can use .parent to look up the parent.
Can I look down to the child?
See what relationships are included in a certain layer.
Copy link to clipboard
Copied
Can I look down to the child?
No—there’s no child property
You can get the object’s properties—this gets the first pageItem’s properties as a text list
var p=app.activeDocument.pageItems[0].properties.toSource();
alert("Properties:\r" + p)
Copy link to clipboard
Copied
Hi Rob Day.
It seems that one scenario has been overlooked.
When no object is selected, how can we indicate that we want to retrieve images outside of the text box?
Copy link to clipboard
Copied
You can get all of the document’s graphics—this is an array not a collection:
var g = app.activeDocument.allGraphics
alert("An array of " + g.length + " graphics")
Copy link to clipboard
Copied
Hi @dublove ,
for a deeper understanding of Collection vs Array ( with getElements() ) read into:
On ‘everyItem( )’ – Part 1
by Marc Autret, June 30, 2010
https://www.indiscripts.com/post/2010/06/on-everyitem-part-1
On ‘everyItem( )’ – Part 2
by Marc Autret, July 19, 2010
https://www.indiscripts.com/post/2010/07/on-everyitem-part-2
Regards,
Uwe Laubender
( Adobe Community Expert )
Find more inspiration, events, and resources on the new Adobe Community
Explore Now