Copy link to clipboard
Copied
I have a long document. I want to find the answer to the options under each question that matches the character style. Do you have any idea? Thanks in advance.
Copy link to clipboard
Copied
Interesting game! …
(^/)
Copy link to clipboard
Copied
Try this code.
#target indesign
var myDoc =app.activeDocument;
var myarray =[];
var myarray_1 = [];
var my_Final = [];
app.findGrepPreferences = app.changeGrepPreferences = null;
app.findGrepPreferences.findWhat = "^\\d";
myFound = myDoc.findGrep();
for(var i=0; i<myFound.length; i++)
{
if(myFound.contents)
{
myarray.push(myFound.contents);
var myjoin = myarray.join("")
}
}
app.findGrepPreferences = null;
app.findGrepPreferences.appliedCharacterStyle = "Blue";
myFound_1 = myDoc.findGrep();
for(var i=0; i<myFound_1.length; i++)
{
if(myFound_1.contents)
{
myarray_1.push(myFound_1.contents);
var myjoin_1 = myarray_1.join("")
}
}
for(a=0; a<myjoin.length&&myjoin_1.length; a++)
{
var my_Final$ =myjoin+myjoin_1;
my_Final.push(my_Final$)
var final_join = my_Final.join("\n")
}
var myFile_path = app.activeDocument.filePath;
var myReport_name = myDoc.name.replace(".indd", ".csv");
var myFinalpath = myFile_path+ "/"+myReport_name;
var myTextFile = new File(myFile_path+"/"+myReport_name)
myTextFile.open("w");
myTextFile.write(final_join)
myTextFile.close();