Copy link to clipboard
Copied
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 s
My getTextSearch(fp) function is searching for plain text not GREP. This searches for GREP:
/**
* Gets results of a text search as an array
* @ param text to search for
* @ 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}
ap
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 o
Copy link to clipboard
Copied
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()
}
Copy link to clipboard
Copied
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()
}
})();
Copy link to clipboard
Copied
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});
}
}
Copy link to clipboard
Copied
Hi@rob day
I'm impressed with your function structure. It's a good guide.
Thank you very much.
I would also like to get the text in the frame, how should I represent it?
Copy link to clipboard
Copied
Hi rob day.
If none of the lines are shown, the way to look for the 1st word may report an error.
Copy link to clipboard
Copied
If none of the lines are shown
Then the script would have to change the geometricBounds of the textframe
Copy link to clipboard
Copied
Hi @rob day
I'm trying to remove the @. in the title note. The following sentence
tf.contents.replace(/@/i, "");
I will, it turns out:
tf.contents = tf.contents.replace(/\@/gi, "");
But I don't know how this is case insensitive?
var res = getTextSearch("(?i)abc")
doesn't seem to work.
getTextSearch(); does not seem to support complex expressions.
thank you.
Copy link to clipboard
Copied
My getTextSearch(fp) function is searching for plain text not GREP. This searches for GREP:
/**
* Gets results of a text search as an array
* @ param text to search for
* @ 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()
}
Copy link to clipboard
Copied
How is the front side going to be represented?
var res = getGrepSearch("@|AA|BB");
doesn't seem right
I changed it to:
function getGrepSearch(fp) {
...
return app.findGrep()
}
is right.
It's really more efficient to use regulars directly.
What is the new “s” you added?
Copy link to clipboard
Copied
I changed it to:
No, don’t change the function, call it to get an array of results like this:
//a returned array of results fom the selected text
var res = getGrepSearch("@|AA|BB", app.selection[0].parentStory)
alert(res)
for (var i = 0; i < res.length; i++){
//alert(res[i])
};
/**
* 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()
}
Copy link to clipboard
Copied
Hi rob day.
Is it like this?
var res = getGrepSearch("@|AA|BB", app.selection[0].parentStory);
alert(res);
This doesn't work well.
Because my selection could potentially contain image frames.
If I really want to add selection.
then two states will do:
1. multiple images and text frames are selected (here comes the trouble, you still have to distinguish between image frames and text frames)
2. No selection, on the entire document. (That's what I did earlier, and this is actually enough)
Copy link to clipboard
Copied
The 2nd parameter has to be an object that takes the findGrep method— Application, Document, Text, TextPath, Character, Paragraph, line, etc. (not images)—you'll have to get those objects from you selection.
Copy link to clipboard
Copied
Whatever, it's enough for now.
I'll look into getting text frame from selections when I'm competent.
Copy link to clipboard
Copied
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());
}
Copy link to clipboard
Copied
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()
}
Copy link to clipboard
Copied
Success. var res = getGrepSearch(“@|AA|BB”)
var res = getGrepSearch("@|AA|BB")
I didn't use the 2nd parameter, and it worked, but, sometimes there was an overflow that would report an error.
It works perfectly. No more tossing.
I need to learn the structure sometime.
Thank you very much.
Copy link to clipboard
Copied
I didn't use the 2nd parameter, and it worked
Don’t know how that’s possible, 2nd parameter is required
Copy link to clipboard
Copied
Yes, the second parameter is required to be kept.
Without the second argument,
var res = getGrepSearch(“@|AA|BB”) will retrieve from the unselected items.
But with the second parameter, it will error for overflow text.
I've come up with a solution now:
Apply object style capC immediately after
"var res = getGrepSearch("@|AA|BB",sa[k]))",
because capC has frame height adaption. The overflow text will then expand.
But I don't know how to get it here, res[k] seems to be non-existent.
res[k].parent.characters[0].parentTextFrames[0].appliedObjectStyle = capC;
report an error: undefined is not anobject
Copy link to clipboard
Copied
Needs to be string—"capC" not capC
Copy link to clipboard
Copied
capC is fine, this is the string from my.json.
It's this line that's problematic. and res[k] doesn't seem to exist:
alert(res[k].parent.characters[0].parentTextFrames[0]);
Copy link to clipboard
Copied
Simplified, remove useless information.
Copy link to clipboard
Copied
Simplified, remove useless information.
Copy link to clipboard
Copied
Not sure what your res[k] is, but in my last example res[j] would be the found texts.
Copy link to clipboard
Copied
Hi rob day.
Sorry for not getting back to you in time.
It's a bit messy, I'll re-post the code.
Purpose:
find the text box containing “@”, apply object style (single line sl, multi-line mL)
Two possibilities:
01. If you do not select any object, for the entire document to perform.
02. If you select the image and text Frame, for the selected text Frame.
I'm trying to:
First, locate the text box so that the overflow text is released.
Then start the subsequent operations.
Bugs found:
01. If there is only one line of text, and the text has overflow will report an error.
02. Failure to execute for the selected (if you execute a few more times, found that your selection does not work, the script always performs the operation on the entire document)
var doc = app.activeDocument,
item = doc.selection[0];
if (!item) {
noselectMain();
}
if (item) {
selectMain() ;
}
// no select any object
function noselectMain() {
//single line
var sL = newObjStyle(app.activeDocument, "capC");
//muti line
var mL = newObjStyle(app.activeDocument, "capL");
//the search results as an array
var res = getGrepSearchNos("@");
//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]
//Clear overtype
tf.clearObjectStyleOverrides();
tf.parentStory.paragraphs[0].clearOverrides();
tf.texts[0].appliedCharacterStyle = app.documents[0].characterStyles[0];
}
}
// selected image and textframe
function selectMain() {
//single line
var sL = newObjStyle(app.activeDocument, "capC");
//muti line
var mL = newObjStyle(app.activeDocument, "capL");
var sa = app.selection;
var s = app.documents[0].selection;
//alert(sa);
for (var k = 0; k < sa.length; k++) {
//get text frames in the selection
if ("TextFrame" == sa[k].constructor.name) {
if (sa[k].overflows) {
sa[k].fit(FitOptions.FRAME_TO_CONTENT)
}
//a returned array of results fom the selected text
var res = getGrepSearch("@")
var tf;
for (var i = 0; i < res.length; i++) {
tf = res[i].parent.characters[0]
tf.appliedObjectStyle = mL;
//Clear overtype
//tf.clearObjectStyleOverrides();
//tf.parentStory.paragraphs[0].clearOverrides();
//tf.texts[0].appliedCharacterStyle = app.documents[0].characterStyles[0];
};
}
}
/**
* Gets results of a text search as an array
* @ param text to search for
* @ 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 app.findGrep()
return s.findGrep()
}
function getGrepSearchNos(fp) {
app.findGrepPreferences = app.changeGrepPreferences = app.findChangeGrepOptions = null;
app.findChangeGrepOptions.properties = { includeHiddenLayers: true, includeLockedLayersForFind: true, includeLockedStoriesForFind: true, includeMasterPages: true }
app.findGrepPreferences.findWhat = fp;
//return app.findGrep()
return s.findGrep()
}
modify 2025.07.12 Increased overflow
Find more inspiration, events, and resources on the new Adobe Community
Explore Now