简体   繁体   中英

Select all text in thread in InDesign?

I'm attempting to select all text in a thread in InDesign CS4 so I can call another script (not made by me) on the selected text using doScript . This question makes me think it is possible. I tried frame.contents.select(); , but this gives the error "frame.contents.select is not a function."

How can I select the contents of a thread in InDesign using extendscript / javascript?

( 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM