1 Reply Latest reply on Aug 22, 2015 2:49 AM by Peter Kahrel

    Randomly assign font to characters



      I'm trying to figure out a way to randomly assign one of a set of fonts to each character in the document.
      I've searched the internet and found the below script that is supposed to work for Microsoft Word (I'm still a novice when it comes to scripting, and the script is sort of old, so I haven't succeeded in making it work).

      I wanted to see if anyone knew of a way to use this concept and adapt a script for InDesign that would randomly assign a font to each character in the document from a list of fonts.


      Set objWord = CreateObject("Word.Application")

      objWord.Visible = True



      Set objDoc = objWord.Documents.Open("C:\Scripts\Test.doc")



      Set objRandom = CreateObject("System.Random")



      intLow = 1

      intHigh = 5



      Set objRange = objDoc.Range()

      Set colCharacters = objRange.Characters



      For Each strCharacter in colCharacters

          intRandom = objRandom.Next_2(intLow,intHigh)


          Select Case intRandom

              Case 1 strCharacter.Font.Name = "Arial"

              Case 2 strCharacter.Font.Name = "Times New Roman"

              Case 3 strCharacter.Font.Name = "Courier New"

              Case 4 strCharacter.Font.Name = "Forte"

          End Select



      Any help is greatly appreciated!!

        • 1. Re: Randomly assign font to characters
          Peter Kahrel Adobe Community Professional & MVP

          You should refine your googling : "indesign apply random font" gives you numerous links, the more interisting of which is Random font script?

          But that doesn't apply random fonts to characters. This does (select a text frame or some text):


          fontNames = ['Arial', 'Times New Roman', 'Courier New', 'Forte'];
          ch = app.selection[0].parentStory.characters.everyItem().getElements();
          for (i = ch.length-1; i >= 0; i--) {
              ch[i].appliedFont = fontNames[Math.floor(Math.random()*4)];


          Expect very, very long running times on large documents.