How to Select All Textframes in Document, and Retrieve the Text in Adobe Indesign

Indesign scripting to get all textframes of a page in order

Basically you will have to start with any text frame and from this find all linked text frames and then in a third step collect just those that are on your page. Here is how you could go about it:

// get your document and your page somehow
var doc = app.activeDocument;
var myPage = doc.pages[1];

// get any text frame on your page and from its parent story get the
// text containers which is an array of all text frames that contain
// the linked text story
var someTextFrame = myPage.textFrames[0];
var textContainers = someTextFrame.parentStory.textContainers;

// loop over all text containers in order and collect those that are
// on your page
var textFramesInOrder = [];
for (var i = 0; i < textContainers.length; i++) {
if(textContainers[i].parentPage === myPage) {
textFramesInOrder.push(textContainers[i]);
}
}

// now textFramesInOrder holds all the text frames of the page in correct order

Selecting textFrames inside of a group in InDesign CS6

Groups on a page are page.groups ... but you don't need this anyway. Fabian's answer is good, but it doesn't take groups-in-groups into account -- nor clipping masks, nor text frames inside tables and footnotes (etc.).

Here is an alternative approach: allPageItems is pretty much guaranteed to return all page items, of all kinds and persuasion, inside groups or other frames or whatnot. You can inspect, then process, each of them in turn, or build an array of text frames to work with at leisure:

allframes = app.activeDocument.allPageItems;
textframes = [];
for (i=0; i<allframes.length; i++)
{
if (allframes[i] instanceof TextFrame)
textframes.push(allframes[i]);
}
alert (textframes.length);

Select all text in thread in InDesign?

(Any_text_item).contents is a plain text interface only; it does not directly access InDesign's native Text object, but instead text is translated to and from a regular Javascript string. So selecting the Javascript text (if possible) would do nothing to the text in the InDesign document itself.

To get all threaded text from any text frame (or other object), you can use its parentStory object. To select the (native) text, target its texts[0] property and use select on that:

frame.parentStory.texts[0].select();

If you can locate at what point the "current selection" is checked, you can add the following lines immediately before it:1

if (app.selection.length == 1 && app.selection[0].hasOwnProperty("previousTextFrame"))
{
// alert ('we must be a text frame!');
app.selection[0].parentStory.texts[0].select();
}

For example, in the script markdownId.jsx that would be near around line 29, just after

tagset = findTagSet();
if (app.selection.length > 0)
{ // <- add the new lines immediately below this one, above the next
if (app.selection.length == 1 && app.selection[0].hasOwnProperty('baseline') && app.selection[0].length > 1)

¹ Best is to test for a property of which you are sure none 'unwanted' objects have. Earlier, I used parentStory but realized that a plain text selection also has this property, and so it cannot differ between a regular selection and a text frame. For previousTextFrame you can be sure that only text frames and text paths are the right kind of object.

How to copy all the contents of various threaded textframes to another textframe in indesign with javascript?

Here's a simple solution:

var doc = app.activeDocument;

var page = doc.pages[0];

var frame1 = page.textFrames[0];
var frame2 = page.textFrames[1];

frame1.texts.everyItem().select();
app.copy();

frame2.texts.everyItem().select();
app.paste();

How can I make all the text in an InDesign document black using ExtendScript?

The swatch you get that way is invalid, even if you try to get it by name (itemByName) don't ask me why, but it is better to use Color objects. For example you could do this to create the color:

var color = document.colors.itemByName("myblack");
if(color==null){
color = document.colors.add();
color.name = "myblack";
color.colorValue = [100,100,100,100];
}

Then apply it directly to the fillColor property.

(one remark, textFrames.fillColor will not change the texts color, but the TextFrame background... I think you want to iterate the texts on each TextFrame and change their fillColor.)

grab the count of selected textframe indesign

If you want to allow a selection of multiple text frames, you first need to cycle through the selection to collect all selected items which are actually text frames and then in a second step loop over all these collected text frames.

This should do, what you need:

var sel = app.selection;
var selectedTextFrames = [];

for (var i = 0; i < sel.length; i++) {
if(sel[i] instanceof TextFrame) {
selectedTextFrames.push(sel[i])
}
}

if(!selectedTextFrames.length) {
alert("Please select one or multiple text frames");
exit();
}

for (var i = 0; i < selectedTextFrames.length; i++) {
// do something with each selected text frame
}

alert(i + " text frame(s) have been processed.");


Related Topics



Leave a reply



Submit