Article View: adobe.scripting.indesign
Article #10237[JS CS2] Open a text file and parse line by line
From: chad_edge
Date: Wed, 28 Jun 2006 19:58
Date: Wed, 28 Jun 2006 19:58
63 lines
2589 bytes
2589 bytes
I have the following in my .pil files (yes, me again):
object {
origin { 0 2300 }
dimensions { 168000 225000 }
id "692596902"
user-name "692596902"
rc-name "692596902"
application {
app-name "ATEX-FPO-DUMMY-CONTROL"
string { major-type "ADV" }
string { advertisers-name "XXX" }
string { ad-description "T-DAY STWD PG 1: WEP" }
string { ad-number "692596902" }
}
application {
app-name "ATEX-ARCHITECT-ADINFO"
string { object-type "AD" }
string { columns "6.0" }
string { lines "2250" }
string { advertiser "XXX" }
string { description "T-DAY STWD PG 1: WEP" }
string { zone "OZON" }
string { merchandise-code "2050" }
}
application {
app-name "ATEX-COLOR"
string { color "SP" }
}
}
This is basically a text file. I'd like to use Javascript to do the following:
1. Open this text file (XXX.pil)
2. Read in each line (an array of strings?)
3. parse the lines (regexp) looking for things like 'zone "OZON"'
4. output the lines I need to an alert (debug step)
5. use the values of the regexp'd lines in my placement (placing textframes)
My problem: Yes, you may say I have many problems, but I'm having a bitch of a time getting the files to open and even output as an alert. Here's what I have for opening the file:
// 1. get a .pil file
var pilFileLocation = "[[path to files]]/";
var pilFile = pilFileLocation+"XXX.pil";
// 2. open the .pil file
var openPilFile = File(pilFile);
//myDocument.place(openPilFile);
var openPilFileContents = openPilFile.open("r");
var openPilFileLength = openPilFileContents.length;
if(openPilFileContents==true){
alert("Your .pil file has been opened. (length: "+openPilFileLength+")");
// do something
} else {
alert("Sorry, it doesn't look like we could open the .pil file.");
}
I get a true for the openPilFile.open("r");
However, openPilFileLength returns undefined.
Any takers?
Chad
Technical Details
Message-ID:
<3bc0c041.-1@webcrossing.la2eafNXanI>Path:
arc1-ca.pugleaf.net!g2news2.google.com!news2.google.com!news.germany.com!news.datemas.de!news.albasani.net!news.ecp.fr!news.stben.net!webcrossingShow Full Headers
Complete Article Headers
X-Google-Thread: f939a,3bc9981b28d99c9,start X-Google-Attributes: gidf939a,public X-Google-Language: ENGLISH,ASCII-7-bit From: chad_edge@adobeforums.com Newsgroups: adobe.scripting.indesign Subject: [JS CS2] Open a text file and parse line by line Message-ID: <3bc0c041.-1@webcrossing.la2eafNXanI> Date: Wed, 28 Jun 2006 12:58:26 -0700 Lines: 68 MIME-Version: 1.0 Content-Type: text/plain; charset="ISO-8859-1" Content-Transfer-Encoding: 8bit Path: arc1-ca.pugleaf.net!g2news2.google.com!news2.google.com!news.germany.com!news.datemas.de!news.albasani.net!news.ecp.fr!news.stben.net!webcrossing