• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

First Read and later write in .csv file

Enthusiast ,
Nov 08, 2016 Nov 08, 2016

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

Screen Shot 2016-11-08 at 12.36.09.png

Write .csv:

Screen Shot 2016-11-08 at 12.36.15.png

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

TOPICS
Scripting

Views

598

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Guru , Nov 08, 2016 Nov 08, 2016

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

...

Votes

Translate

Translate
Guide ,
Nov 08, 2016 Nov 08, 2016

Copy link to clipboard

Copied

Yes it is possible to read and writing in same .csv

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guru ,
Nov 08, 2016 Nov 08, 2016

Copy link to clipboard

Copied

Hi Siraj

I'm not too sure what you want to do.

It sounds like you want

  • read the csv
  • get indesign to open the documents and check for fonts
  • write back to the csv file

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Enthusiast ,
Nov 08, 2016 Nov 08, 2016

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,

Screen Shot 2016-11-08 at 14.57.33.png

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).

Screen Shot 2016-11-08 at 14.57.48.png

Thanks in Advance

Siraj

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guru ,
Nov 08, 2016 Nov 08, 2016

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();

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Enthusiast ,
Nov 09, 2016 Nov 09, 2016

Copy link to clipboard

Copied

LATEST

Thank you Trevor,

working fine after a slight modifications...

Again thanks a lot.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines