Hi, I'm new to this, but I hope someone can help me.
The following string get all text in the document.
|var myTexts = app.activeDocument.stories.everyItem().textStyleRanges.everyItem().getElements();|
Is it possible to get only the text object that are in all layers, but not in the Master Pages
your line of code is likely not getting all text in a document.
Example: It will not get text in table cells and text in footnotes or text in Note objects.
But it gets all text style ranges in all stories of a document. Including masters.
Do you want to get text style ranges? Units of text that are formatted exactly the same?
Do you want to get them on "normal" document spreads only (that would include the pasteboards)?
Also including all table text cells and footnotes? Also text in Note objects?
Then I would solve this with a GREP Find action and extract the text style ranges from the found text. For that you have to loop every found instance and concatenate the textStyleRanges.everyItem().getElements() arrays to one array. With that array you can work on. Whatever you like to do with it. But beware: If you like to change formatting of text you will perhaps create new text style ranges or collapse adjacent ones to a single one.
You could restrict the Find action to document spreads excluding masters and you could include footnotes if necessary. The found results would include all nested structures: Tables, tables nested in tables, footnotes, also text in Note objects.
The base GREP on Find What would be a simple:
In code that would be:
app.findGrepPreferences.findWhat = "\\X+";