1

I know, we can define layers(e.g. text layers) as variables and import data to change the contents of these layers.

(Image -> Variables -> Define)

But I have an excel file with lot of rows of texts and their font sizes. Is it possible to define the font size as a variable, as well? or is there another way to import it and don't change it manually?

3
  • 1
    I think you'd need scripting. Variables don't typically refer to structure only content.
    – Scott
    Apr 20 at 20:24
  • @Scott Thanks, you're right... I achieved it with scripting.
    – Milad
    Apr 21 at 21:02
  • Feel free to answer if you have a solution @Milad :)
    – Scott
    Apr 21 at 21:20

1 Answer 1

3

I wrote a small code to change the font-size:

this.openExcelFile();

function openExcelFile()
{
    var excelFile = File("H:/App/Banner/script/Txt.csv");
    excelFile.open("r");
    
    var wholeFile = excelFile.read().split("end");
    excelFile.close();

    for(var i = 1; i <= wholeFile.length; i++)
    {
        this.addToPhotoshop(wholeFile[i]);
    } 
}

function addToPhotoshop(rows)
{
    rows = rows.split(";");

    var txt = rows[0].replace(/^\s+|\s+$/gm,'');
    var writer = decodeURI(rows[1].replace("\n", "\r").replace("\n", "\r").replace("\n", "\r").replace("\n", "\r"));
    var smiley     = rows[2];
    var fontSize   = Math.floor(parseInt(rows[3]));

    var activeDoc = app.activeDocument;

    var mainLyricLayer  = activeDoc.layerSets.getByName("lyrics").artLayers.getByName("mainLyric").textItem;
    var mainRapperLayer = activeDoc.artLayers.getByName("writer").textItem;
    var mainSmileyLayer = activeDoc.artLayers.getByName("smiley").textItem;
    
    mainLyricLayer.contents = rapperText + " " + smiley;
    mainLyricLayer.size     = fontSize;

    mainRapperLayer.contents = rapperName;

    this.exportJpg(rows[11]);
    
    return;
}

function exportJpg(counter) 
{  
    var fullFilePath = "H:/App/Banner/script/export/" + app.activeDocument.name.split('.')[0] + "-" + counter + '.jpeg'
    var idsave = stringIDToTypeID("save");
    var desc5 = new ActionDescriptor();
    var idas = stringIDToTypeID("as");
    var desc6 = new ActionDescriptor();
    var idextendedQuality = stringIDToTypeID("extendedQuality");
    desc6.putInteger(idextendedQuality, 12);
    var idscans = stringIDToTypeID("scans");
    desc6.putInteger(idscans, 5);
    var idmatteColor = stringIDToTypeID("matteColor");
    var idmatteColor = stringIDToTypeID("matteColor");
    var idnone = stringIDToTypeID("none");
    desc6.putEnumerated(idmatteColor, idmatteColor, idnone);
    var idJPEG = stringIDToTypeID("JPEG");
    desc5.putObject(idas, idJPEG, desc6);
    var idin = stringIDToTypeID("in");
    desc5.putPath(idin, new File(fullFilePath));
    var iddocumentID = stringIDToTypeID("documentID");
    desc5.putInteger(iddocumentID, 219);
    var idlowerCase = stringIDToTypeID("lowerCase");
    desc5.putBoolean(idlowerCase, true);
    var idsaveStage = stringIDToTypeID("saveStage");
    var idsaveStageType = stringIDToTypeID("saveStageType");
    var idsaveSucceeded = stringIDToTypeID("saveSucceeded");
    desc5.putEnumerated(idsaveStage, idsaveStageType, idsaveSucceeded);
    executeAction(idsave, desc5, DialogModes.NO);
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.