Copy link to clipboard
Copied
When I check a script I use the alert to see if the code is working, such as "Current tag is body".
Is there a function that outputs alert results to a file? For example, a way to send to a file all
of the paragraph tags that are used in a document. (The actual code could be a loop). I could
use this as a start to produce what I really want, an array of all the valid tags, and then print to a file
a list of all the "rogue" tags that are not in the valid list
Copy link to clipboard
Copied
Check the JavaScript Tools Guide for details about the File object. Basically, it works more or less like this:
var oFile = new File ( /* full path name as text string */ );
oFile.open( "w" ); /* use "a" to append, "w" to remove existing text.
oFile.writeln ( "Whatever you want to write in there" );
oFile.close ( );
Ciao
Jang
Copy link to clipboard
Copied
Here's the code I have, but the Extendscript debugger says oFile.open is not a function, is this only for javascript?
Thanks,
Keith
function processDoc (doc) {
//Process the paragraphs and tables in the main document flow
var textList, count = 0, i = 0, tbl = 0, pgf = 0;
var oFile = "c:\myname\tags-list.txt";
// Turn off the document display to speed the script and
// prevent screen flicker.
if (app.Displaying == 1) {
app.Displaying = 0;
}
//Process each top-level paragraph in document
oFile.open("a");
pgf = doc.MainFlowInDoc.FirstTextFrameInFlow.FirstPgf;
while (pgf.ObjectValid()) {
//!! applyNewPgfFmt(pgf,doc);
oFile.Writeln(pgf.Name);
pgf = pgf.NextPgfInFlow;
}
oFile.close();
Copy link to clipboard
Copied
OK, was in a hurry, see that the new is a resreved word, this should be closer, there are no errors but no text output, I'll keep trying...
//Process the paragraphs and tables in the main document flow
var textList, count = 0, i = 0, tbl = 0, pgf = 0;
var tagsFile = new File ("C:\extend\tag_list.txt")
// Turn off the document display to speed the script and
// prevent screen flicker.
if (app.Displaying == 1) {
app.Displaying = 0;
}
//Process each top-level paragraph in document
tagsFile.open("a");
pgf = doc.MainFlowInDoc.FirstTextFrameInFlow.FirstPgf;
while (pgf.ObjectValid()) {
//!! applyNewPgfFmt(pgf,doc);
tagsFile.writeln (pgf.NextPgfInFlow);
// pgf = pgf.NextPgfInFlow;
}
tagsFile.close();
Copy link to clipboard
Copied
Keith,
There are a couple of problems with your script.
1. You need to 'escape' the backslash in strings. So the code for creating your file should look like this:
var tagsFile = new File ("C:\\extend\tag_list.txt")
2. You cannot write the pgf to a text file as the pgf is an object that contains a whole lot of properties. I am not sure which property you want to write to the text file, but if you want to write the paragraph format tag, you should use:
tagsFile.writeln (pgf.NextPgfInFlow.Name);
Good luck
Jang
Copy link to clipboard
Copied
Thanks, I got it to work, with using foraward slashes and an extra step, is there an advantage to your code? Sometimes mine will lock up Frame:
function processDoc (doc) {
//Process the paragraphs and tables in the main document flow
var textList, count = 0, i = 0, tbl = 0, pgf = 0;
var tagsFile = new File ("/<path>/For_Keith/tag_list.txt")
alert (tagsFile);
// Turn off the document display to speed the script and
// prevent screen flicker.
if (app.Displaying == 1) {
app.Displaying = 0;
}
//Process each top-level paragraph in document
tagsFile.open("w");
pgf = doc.MainFlowInDoc.FirstTextFrameInFlow.FirstPgf;
while (pgf.ObjectValid()) {
//!! applyNewPgfFmt(pgf,doc);
tagsFile.writeln (pgf.Name);
pgf = pgf.NextPgfInFlow;
}
tagsFile.close();
}
Copy link to clipboard
Copied
Hi Keith,
I can't tell why Frame sometimes locks up, as I don't know what your applyNewPgfFmt function looks like. I would keep displaying on until the code is perfected and well-tested, then use the debug mode to step through until it hits the spot where Frame locks up. You can also write debug messages to either a text file or the console, simply by using the function Console( "message" );
Good luck
Jang