Forum Replies Created

  • Alex Hayward

    April 13, 2022 at 10:15 pm in reply to: CSV driven graphics

    As far as I’m aware, the only way you are able to update an image via .csv data would be using a script. Try something like this:

    function runWeatherScript(){

    app.beginUndoGroup("Run Weather Script");

    var masterComp = findItem("CHANGE TO MASTER COMP NAME",0);

    // Error check, makes sure script has a comp to target

    if(masterComp == null){

    alert("Master comp not found");

    return

    };

    // Import the CSV file

    var csvFile = File.openDialog("Please select the CSV file containing the weather info", "CSV Files:*.csv");

    // Open the file and push all data into an array

    var csvData = [];

    csvFile.open("r");

    do {

    csvData.push(csvFile.readln());

    } while(!csvFile.eof);

    csvFile.close();

    //Loop through each line of the CSV file - start on 1st line of actual data

    for (var i = 1; i < csvData.length; i++) {

    // Seperate current row into each cell

    var curRow = csvData[i].split(",");

    // Variables for each column, easier to follow

    var city = curRow[0];

    var temp = curRow[1];

    var iconName = curRow[2];

    // Create copy of master comp for us to work in and rename to the city

    var newComp = masterComp.duplicate();

    newComp.name = city;

    // Change city text

    newComp.layer("CHANGE TO CITY TEXT LAYER NAME").property("Source Text").setValue(city);

    // Change temperature text

    newComp.layer("CHANGE TO TEMPERATURE TEXT LAYER NAME").property("Source Text").setValue(temp);

    // Get right icon

    var icon = findItem(iconName,csvData.length)

    // Change Icon

    newComp.layer("CHANGE TO ICON IMAGE LAYER NAME").replaceSource(icon,false);

    }

    app.endUndoGroup();

    }

    function findItem(x,length){

    for (var i = 1; i < app.project.numItems+length; i++) {

    if (app.project.item(i).name === x) {

    return app.project.item(i);

    break;

    }

    }

    }

    var csvData = [];

    runWeatherScript();

    It assumes all the layers you are changing are within the same comp and not pre-composed. Name the layers that will be changing in your project file and update the code to match those names. Let me know if any issues and I’ll try and help 🙂

We use anonymous cookies to give you the best experience we can.
Our Privacy policy | GDPR Policy