Change found text to anchored textFrame
Hi,
I'm trying to find text with specific character style and create a new anchored TextFrame.
The code below works only on first match.
var main = function() {
var doc = app.properties.activeDocument, found, foundlength, selection = app.selection[0]
if ( !doc ) return;
app.findGrepPreferences = null;
app.findGrepPreferences.properties = {
findWhat : ".+",
appliedCharacterStyle : "style1"
};
found = selection.findGrep();
foundlength = found.length
if ( !found.length ) {
alert("Nothing found");
return;
}
for (i = 0; i<foundlength; i++) {
var myNewTextFrame = found[i].insertionPoints[0].textFrames.add();
//myNewTextFrame.appliedObjectStyle = objectStyle;
found[i].move(LocationOptions.AT_BEGINNING, myNewTextFrame.insertionPoints[0]);
}
}
app.doScript(String(main()),ScriptLanguage.JAVASCRIPT,[],UndoModes.ENTIRE_SCRIPT,'main');