1 Reply Latest reply on Jan 21, 2018 10:03 AM by c.pfaffenbichler

    How can I randomly apply one of a limited number of fonts to a set of layered images, in Data Driven Graphics?

    Jackveer Level 1

      Hello,

       

      If you're familiar with 'Data Driven Graphics' aka 'Variables' option in Photoshop, I've the following concern:

       

      1. I want to create 300 Quote graphics using 'Variables' option of Photoshop. I know how to achieve this using Variables.. like giving input text file (which is Text Quotes here) and then assigning Image ids to each quote (all images in same folder)... and achieve this by creating a PSD template.

       

      So far so good...

       

      Now, what I'm unable to achieve is this:

       

      2. How can I choose, not just one font, for type layers (which are Text Quote and Author name here) but randomly apply one of a limited number of fonts to a set of layered images? Let's say I select 2-4 specific fonts and photoshop script should use them randomly for the set.

       

      Is this something achievable?

       

      I've already inquired about this earlier(not exactly for this feature though)... so below are those threads as reference.

       

      1. PS Action needed to batch create quote graphics UNIQUELY

      2. How to batch create quote graphics UNIQUELY with Data Variables or Action Or Script?

      3. How to select multiple fonts in Data Driven Graphics?

       

      A solution is much needed.Thank you.

       

      c.c. c.pfaffenbichler Trevor.Dennis EFinnegan Bojan Živković

        • 1. Re: How can I randomly apply one of a limited number of fonts to a set of layered images, in Data Driven Graphics?
          c.pfaffenbichler Level 9

          Not sure if this would be useful in your workflow but the following would change all Type Layers’s fonts to one from an Array of fonts.

           

          // 2017, use it at your own risk;

          #target photoshop

          if (app.documents.length > 0) {

          var myDocument = app.activeDocument;

          var theFonts = ["Impact", "Courier-Bold", "Times-BoldItalic"];

          var theNumberOfFonts = theFonts.length;

          var theTypeLayers = collectTypeLayers ();

          for (var m = 0; m < theTypeLayers.length; m++) {

          changeFont (theFonts[Math.floor (Math.random()*theNumberOfFonts)], theTypeLayers[m][1])

          };

          };

          ////// collect type layers //////

          function collectTypeLayers () {

          // the file;

          var myDocument = app.activeDocument;

          // get number of layers;

          var ref = new ActionReference();

          ref.putEnumerated( charIDToTypeID("Dcmn"), charIDToTypeID("Ordn"), charIDToTypeID("Trgt") );

          var applicationDesc = executeActionGet(ref);

          var theNumber = applicationDesc.getInteger(stringIDToTypeID("numberOfLayers"));

          // process the layers;

          var theLayers = new Array;

          for (var m = 0; m <= theNumber; m++) {

          try {

          var ref = new ActionReference();

          ref.putIndex( charIDToTypeID( "Lyr " ), m);

          var layerDesc = executeActionGet(ref);

          var layerSet = typeIDToStringID(layerDesc.getEnumerationValue(stringIDToTypeID("layerSection")));

          var isBackground = layerDesc.getBoolean(stringIDToTypeID("background"));

          // if not layer group collect values;

          if (layerSet != "layerSectionEnd" && layerSet != "layerSectionStart" && isBackground != true && layerDesc.hasKey(stringIDToTypeID("textKey")) == true) {

          var theName = layerDesc.getString(stringIDToTypeID('name'));

          var theID = layerDesc.getInteger(stringIDToTypeID('layerID'));

          theLayers.push([theName, theID])

          };

          }

          catch (e) {};

          };

          return theLayers

          };

          ////// change font //////

          function changeFont (theFont, theID) {

          // =======================================================

          var idsetd = charIDToTypeID( "setd" );

              var desc2 = new ActionDescriptor();

              var idnull = charIDToTypeID( "null" );

                  var ref1 = new ActionReference();

                  var idPrpr = charIDToTypeID( "Prpr" );

                  var idTxtS = charIDToTypeID( "TxtS" );

                  ref1.putProperty( idPrpr, idTxtS );

                  ref1.putIdentifier(charIDToTypeID( "TxLr" ), theID);

              desc2.putReference( idnull, ref1 );

              var idT = charIDToTypeID( "T   " );

                  var desc3 = new ActionDescriptor();

                  var idfontPostScriptName = stringIDToTypeID( "fontPostScriptName" );

                  desc3.putString( idfontPostScriptName, theFont );

              desc2.putObject( idT, idTxtS, desc3 );

          executeAction( idsetd, desc2, DialogModes.NO );

          };