Article View: adobe.photoshop.scripting
Article #2090Re: Read a text file in JavaScript
From: matthewrubino
Date: Wed, 23 Jun 2004 18:02
Date: Wed, 23 Jun 2004 18:02
59 lines
2591 bytes
2591 bytes
Here is how to do this in JavaScript. It also brings up a dialog to prompt the user to select the text file which will be used to set variables.
// Set input and output file paths as variables
var inPath = "S:/tmpPhotoRotate/intif/";
var outPath = "S:/tmpPhotoRotate/outtif/";
// Open a dialog to prompt user to select a text file
var openFile = File.openDialog ("Select a text file", "Text Files:*.txt");
// Open the text file and set the contents as
// array variables for input file name, output file name
// and rotation angle
if(openFile.open('r'))
{
// Turn the dialog display off
app.displayDialogs = DialogModes.NO;
var aLine
// While Loop
while(aLine = openFile.readln())
{
// Create the array
var elements = aLine.split(",");
var eleInFileName = new File (inPath + elements[0]);
eleAngle = elements[2];
fltAngle = parseFloat(eleAngle); // Convert string to floating-point number
eleOutFileName = outPath + elements[1];
// Now open the image file
var docRef = app.open(eleInFileName);
// Now rotate the image on the canvas
docRef.rotateCanvas(fltAngle);
// Now save the rotated image as a TIFF
tifFile = new File(eleOutFileName);
tifSaveOptions = new TiffSaveOptions();
tifSaveOptions.alphaChannels = false;
tifSaveOptions.annotations = false;
tifSaveOptions.byteOrder = ByteOrder.IBM;
tifSaveOptions.embedColorProfile = true;
tifSaveOptions.imageCompression = TIFFEncoding.NONE;
//tifSaveOptions.jpegQuality = default;
//tifSaveOptions.layerCompression = default;
tifSaveOptions.layers = false;
tifSaveOptions.saveImagePyramid = false;
tifSaveOptions.spotColors = false;
tifSaveOptions.transparency = false;
app.activeDocument.saveAs(tifFile, tifSaveOptions, false,
Extension.LOWERCASE);
// Close the active document
app.activeDocument.close();
}
openFile.close();
}
Technical Details
Message-ID:
<3bb46cda.4@webx.la2eafNXanI>Path:
arc1-ca.pugleaf.net!g2news1.google.com!news2.google.com!news.maxwell.syr.edu!eusc.inter.net!newsfeed01.sul.t-online.de!t-online.de!webxReferences:
<3bb46cda.-1@webx.la2eafNXanI>Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: f5839,de9f0bb7d687e82c,start X-Google-Attributes: gidf5839,public From: matthewrubino@adobeforums.com Path: arc1-ca.pugleaf.net!g2news1.google.com!news2.google.com!news.maxwell.syr.edu!eusc.inter.net!newsfeed01.sul.t-online.de!t-online.de!webx Newsgroups: adobe.photoshop.scripting Subject: Re: Read a text file in JavaScript Message-ID: <3bb46cda.4@webx.la2eafNXanI> Date: Wed, 23 Jun 2004 11:02:09 -0700 References: <3bb46cda.-1@webx.la2eafNXanI> Lines: 63 MIME-Version: 1.0 Content-Type: text/plain; charset="ISO-8859-1" Content-Transfer-Encoding: 8bit