Hey everyone! Happy to be here.
Does anyone have a really well commented script that explains what is going one when trying to get info out of a CSV file?
I have started a script, but I can not tell where I am going wrong. Here is what I am trying to achieve:
1. I have a CSV file with ~100 rows. Each row has 5 pieces of data...
(1. Local Filepath to an image) (2. Title of Movie) (3. Runtime) (4. Rating) (5. Description)
2. I am attempting to select a random row from the 100 (this is what I need help with), and populate the data associated into an active photoshop document (I got this part covered).
Here is what I have so far, but I'm not sure I'm headed in the right direction. I have commented in some questions, in the code. The randomizer isn't working and I can't figure out how to get a specific column's data into a variable. Anyone have any insight?
var myCSV = new File('ENTER-FILEPATH-HERE/the-csv.csv'); myCSV.open('r');
function getRandomInt() {
return Math.floor(Math.random() * (99 - 2 + 1)) + 2; }
while (!myCSV.eof) {
// myCSV.readln() only returns the data that is the last row in the CSV file, no matter what I put in the "()" How do I manipulate this?
var lines = myCSV.readln(getRandomInt());
var lineItems = new Array(); lineItems = lines.split(","); }
// My check to see what data I'm getting. I always get back the last row of data in the array.
$.writeln(lineItems);
// Does the [1] refer to the column to get the data from? Or am I misunderstanding this? How do I select the appropriate column to put into the variable?
var arrImage = lineItems[1];
var imageRef = File(arrImage);
// This is where Photoshop gets hung up. The filepath isn't attached to the imageRef variable.
var docRef = app.open(imageRef);
myCSV.close();
I appreciate any help!
Edit- formatting