Trying to Remove only Words in Black Color from Text Frames not other Words
Hi Experts,
Im Trying to Remove words in Black Color in text frames in the current document, the code is working but it removes so much and not working accuratley and some times removes word in black with red colored characters! as show here in the video :
https://drive.google.com/file/d/1XN6pQNsyZwh1u87Av_r9ZPKZMGLQIcQR/view?usp=sharing
i want only to remove all the words in black color, but any word is mixed with another color like red i want to keep it and thanks in advance :
//DESCRIPTION : Remove Words Colored in Black (Not Working Accurate!)
//UNDO Enabled
app.doScript(CatchMyError, ScriptLanguage.JAVASCRIPT, undefined, UndoModes.ENTIRE_SCRIPT, "Remove Words Colored in Black");
//RemoveBlackWords();
//Error Catcher for Function
function CatchMyError(){
try {
RemoveBlackWords();
//Catch Error
} catch (myError) {
alert (myError,"ERROR!");
exit();
}
}
function RemoveBlackWords(){
var myDoc = app.documents[0];
var MyTextFrames = myDoc.textFrames.everyItem().getElements();
for( var i = 0; i<MyTextFrames.length; i++ ){
for (j=0; j < MyTextFrames[i].paragraphs.length; j++){
for (w=0; w < MyTextFrames[i].paragraphs[j].words.length; w++){
//if Words in Black Color found it Shouid be Removed! But not all Word Removed! and Some times Extra Words Removed!
if(MyTextFrames[i].paragraphs[j].words[w].fillColor == myDoc.colors.itemByName("Black")){
MyTextFrames[i].paragraphs[j].words[w].remove();
}
}
}
}
}
