Copy link to clipboard
Copied
Hello!
I'm trying to find a way to delete all text frames witch has the word "abc".
I found this script from https://forums.adobe.com/thread/690303 but it doesn't delete all the text frames with the "word" I want.
Does anyone can help me?
Thank you!
app.findGrepPreferences = NothingEnum.nothing;
app.changeGrepPreferences = NothingEnum.nothing;
app.findGrepPreferences.findWhat = "my+.+grep"; // << Edit your GREP here
with(app.activeDocument) {
for(Counter = 0; Counter < textFrames.length; Counter++) {
var MyResult = textFrames.item(Counter).findGrep();
if (MyResult.length == 0) {
textFrames.item(Counter).remove();
}
}
}
var main = function(){
var doc = app.properties.activeDocument;
if ( !doc ) return;
app.findGrepPreferences = app.changeGrepPreferences = null;
app.findGrepPreferences.findWhat = "abc"; // << Edit your GREP here
var found = doc.findGrep();
var n = found.length, text, tf;
while ( n-- ) {
text = found
; if ( !text.isValid ) continue;
if ( !text.parentTextFrames.length ) continue;
text.parentTextFrames[0].remove();
}
}
var u;
app.doScript ( "main()",u,u,UndoModes.ENTIRE_SCRIPT, "ABC" );
Copy link to clipboard
Copied
var main = function(){
var doc = app.properties.activeDocument;
if ( !doc ) return;
app.findGrepPreferences = app.changeGrepPreferences = null;
app.findGrepPreferences.findWhat = "abc"; // << Edit your GREP here
var found = doc.findGrep();
var n = found.length, text, tf;
while ( n-- ) {
text = found
; if ( !text.isValid ) continue;
if ( !text.parentTextFrames.length ) continue;
text.parentTextFrames[0].remove();
}
}
var u;
app.doScript ( "main()",u,u,UndoModes.ENTIRE_SCRIPT, "ABC" );
Copy link to clipboard
Copied
Hi Loic,
your script works for not threaded text frames.
If we consider stories that flow through more than one text frame, we have to be very cautious.
For this case I would first remove the text of the frame and then the frame itself.
Hm… And there could be more than one parent text frame for one single instance of found text.
Regards,
Uwe
Copy link to clipboard
Copied
It works perfectly!!
Thank you very much Logic.Aigon!!
Kind regards!
Copy link to clipboard
Copied
Hi Uwe,
You are right and thanks for pointing this. I think now our friend has everything to build his own bulletproof script