Skip to main content
dublove
Legend
July 2, 2025
Answered

“findWhat: ‘@’” can't retrieve content in overflow text?

  • July 2, 2025
  • 1 reply
  • 1716 views
 If the character you're looking for is in the overflow text, findWhat won't help.
Any ideas?
  var queries = [
        { findWhat: '@', objectStyleName: "CapCenter"},
    ];

Maybe have the overflow text expand first in the same text box?

Correct answer rob day

If you chose images and text, how do you differentiate them and target only the text?

 

At the top, I don't know how to exclude non-textframe.

var doc = app.activeDocument,
    item = doc.selection[0];
...

if (('Image' === item.constructor.name) ||
    ('TextFrame' === item.constructor.name)) {
    try {
        noselectMain());
    }

if (!item){
selectMain());
}

 


You would have to loop thru the selected objects and check for text frames:

 

//a mixed selection
var sa = app.selection
for (var i = 0; i < sa.length; i++){
    //get text frames in the selection
    if (sa[i].constructor.name == "TextFrame") {
        //a returned array of results fom the selected text
        var res = getGrepSearch("@|AA|BB", sa[i])
        alert(res)
        for (var j = 0; j < res.length; j++){
            //alert(res[j])
        };   
    } 
};   



/**
* Gets results of a text search as an array 
* @ param the Grep search string 
* @ param the text to search
* @ return result as an array 
*/
function getGrepSearch(fp, s){
    app.findGrepPreferences = app.changeGrepPreferences = app.findChangeGrepOptions = null;
    app.findChangeGrepOptions.properties = {includeHiddenLayers:true, includeLockedLayersForFind:true, includeLockedStoriesForFind:true, includeMasterPages:true} 
    app.findGrepPreferences.findWhat = fp;
    return s.findGrep()
}

1 reply

rob day
Community Expert
Community Expert
July 2, 2025

Try this, it searches the active document for @ symbols and returns them in an array

 

 

//the search results as an array
var res = getTextSearch("@")
alert(res.length + " @ Symbols found")
for (var i = 0; i < res.length; i++){
    alert(res[i].contents)
};


/**
* Gets results of a text search as an array 
* @ param text to search for 
* @ return an array of results
*/
function getTextSearch(fp){
    app.findTextPreferences = app.changeTextPreferences = app.findChangeTextOptions = null;
    app.findChangeTextOptions.properties = {includeHiddenLayers:true, includeLockedLayersForFind:true, includeLockedStoriesForFind:true, includeMasterPages:true} 
    app.findTextPreferences.findWhat = fp;
    return app.activeDocument.findText()
}

 


dublove
dubloveAuthor
Legend
July 2, 2025

Hi rob day~

I found this one too.Also you finished it.

 

I've been studying it for half a day.
I'd like to start by applying a CapC object style to the found text boxes. But I tried half a day without success.

 

I'm also trying to get the contents of the text box.


Still can't tell the hierarchy?
Or is the syntax wrong?

/**
by rob day
original site
https://community.adobe.com/t5/indesign-discussions/how-can-i-search-for-text-in-textframes-even-if-it-is-not-shown/m-p/15367877
**/

(function main() {
    var ra = grepSearch("jpg");
    //reverse loop
    for (var i = ra.length - 1; i > -1; i--) {
        //ra[i].properties = { pointSize: 35, leading: 40 }
        //var os = app.activeDocument.objectStyles.itemByName(capObjCStn);
        //alert(os.name);
        //ra[i].parent.textFrames[0].applyObjectStyle = os;
        ra[i].parent.properties = {
            appliedObjectStyle: app.activeDocument.objectStyles.item(capObjCStn)
        }
    };


    /**
    * Document Grep find returns an array of text objects
    * @ param f the find grep string 
    * @ return an array of found texts 
    */
    function grepSearch(f) {
        app.findGrepPreferences = app.changeGrepPreferences = app.findChangeGrepOptions = null;
        app.findChangeGrepOptions.properties = app.findChangeGrepOptions.properties = { includeFootnotes: true, includeHiddenLayers: true, includeMasterPages: true, wholeWord: false }
        app.findGrepPreferences.findWhat = f;
        return app.activeDocument.findGrep()
    }
})();

 

rob day
Community Expert
Community Expert
July 2, 2025

To get overflow texts’ text frame you could get the first character—this assumes there is at least 1 charcter showing:

 

//the search results as an array
var res = getTextSearch("@")
//make an object style named "CapC"
var os = makeObjStyle(app.activeDocument, "CapC")

//apply the object style to the parent frame
var tf;
for (var i = 0; i < res.length; i++){
    tf = res[i].parent.characters[0].parentTextFrames[0]
    tf.appliedObjectStyle = os
    //alert(tf)
}


/**
* Gets results of a text search as an array 
* @ param text to search for 
* @ return an array of results
*/
function getTextSearch(fp){
    app.findTextPreferences = app.changeTextPreferences = app.findChangeTextOptions = null;
    app.findChangeTextOptions.properties = {includeHiddenLayers:true, includeLockedLayersForFind:true, includeLockedStoriesForFind:true, includeMasterPages:true} 
    app.findTextPreferences.findWhat = fp;
    return app.activeDocument.findText()
}


/**
* Makes a new named ObjectStyle or returns an existing style 
* @ param the document to add the style to 
* @ param style name 
* @ return the new object style 
*/
function makeObjStyle(d, n){
    if (d.objectStyles.itemByName(n).isValid) {
        return d.objectStyles.itemByName(n);
    } else {
        return d.objectStyles.add({name:n});
    }
}