Copy link to clipboard
Copied
Hi All,
Request is below, I need to get an idea for a big concept
1. Open the Indesign document by read the .csv file
2. After open the document, if Missing Font is available, then the Report write it as FAIL
3. Is it possible reading and writing in same .csv
Read .csv
Write .csv:
Sample Code is below:
var txtFile=File(Folder.desktop + "/somefile.csv");
if(File(Folder.desktop + "/test.txt").exists ==false)
{
var txtFile=new File(Folder.desktop + "/somefile.csv");
}
txtFile.open("r")
while(txtFile.eof == false)
{
var myFind = txtFile.readln();
alert("myFind: " + myFind)
var myLine = myFind.split(",");
alert("myLine Comma: " + myLine)
//------------Missing Font Condition Code Here-------------
txtFile.open("e");
txtFile.seek(0, 2);
txtFile.write(" FAIL");
txtFile.close();
}
Thanks in Advance
Siraj
I had something more like the below in mind
...// Not tested even one time
// in a very lazy mode
var csvData, csvFile, l, doc, myTemp_Path;
csvFile = File(Folder.desktop + "/somefile.csv");
csvFile.open("r");
csvData = csvFile.read().split('\n');
csvFile.close();
l = csvData.length;
while (l--){
myTemp_Path = csvData
.split(',')[0]; doc = app.open(File(myTemp_Path));
// Very lazy line, sorry
csvData
= (doc.fonts.everyItem().status.toString().replace(/INSTALLED|\,/g,'').length) ? myTemp_Path + ', Fai
Copy link to clipboard
Copied
Yes it is possible to read and writing in same .csv
Copy link to clipboard
Copied
Hi Siraj
I'm not too sure what you want to do.
It sounds like you want
If the file is not too long it's should be very simple to just read the entire csv, look at the files and then rewrite the the whole csv.
HTH
Trevor
Copy link to clipboard
Copied
Thanks Trevor/Karthik,
Tried the below code using seek(0,2), but not works
seek(0,2) should break the loop and create the FAIL report in the EOF of .csv only
var csvFile=File(Folder.desktop + "/somefile.csv");
csvFile.open("r")
while(csvFile.eof == false)
{
var myFind = csvFile.readln();
var myLine = myFind.split(",");
var myTemp_Path = myLine[0];
alert("myTemp_Path: " + myTemp_Path)
app.open(File(myTemp_Path))
//Missing Font Concept below
var _missingFont_Check = 0;
var myUsedFonts = app.activeDocument.fonts;
for (var i = 0; i < myUsedFonts.length; i++)
{
if (myUsedFonts.status != "1718831470")
{
_missingFont_Check = 1;
}
}
//-----------------Help needed for below lines------------------
if(_missingFont_Check == 1)
{
alert("Document having missing font");
// exit(0);
csvFile.open("e");
csvFile.seek(0, 2); //Suspect seek (0,2)
csvFile.write( "\tFAIL");
csvFile.close()
}
}
Before running the script,
After running the script,
Actually "RRR.indd" file having missing font, by using the above code loop breaks and the report created in last row(abcd.indd).
Thanks in Advance
Siraj
Copy link to clipboard
Copied
I had something more like the below in mind
// Not tested even one time
// in a very lazy mode
var csvData, csvFile, l, doc, myTemp_Path;
csvFile = File(Folder.desktop + "/somefile.csv");
csvFile.open("r");
csvData = csvFile.read().split('\n');
csvFile.close();
l = csvData.length;
while (l--){
myTemp_Path = csvData
.split(',')[0]; doc = app.open(File(myTemp_Path));
// Very lazy line, sorry
csvData
= (doc.fonts.everyItem().status.toString().replace(/INSTALLED|\,/g,'').length) ? myTemp_Path + ', Fail' : myTemp_Path;
}
csvFile.open("w").write(csvData.join('\n')).csvFile.close();
Copy link to clipboard
Copied
Thank you Trevor,
working fine after a slight modifications...
Again thanks a lot.