• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Randomly assign font to characters

New Here ,
Aug 21, 2015 Aug 21, 2015

Copy link to clipboard

Copied

Hi,

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

Next

Any help is greatly appreciated!!

TOPICS
Scripting

Views

1.7K

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Aug 22, 2015 Aug 22, 2015

Copy link to clipboard

Copied

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.appliedFont = fontNames[Math.floor(Math.random()*4)];

}

Expect very, very long running times on large documents.

Peter

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Nov 23, 2017 Nov 23, 2017

Copy link to clipboard

Copied

been using this for a while, very good sir

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Sep 30, 2020 Sep 30, 2020

Copy link to clipboard

Copied

Hi, I am not sure if I am doing this wrong.

I have a 10 page story and am trying to run this script on it. Nothing seems to be changing though.

Is there more to this code that I should be adding?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Sep 30, 2020 Sep 30, 2020

Copy link to clipboard

Copied

Hi Anna,

one explanation why this script is not working for you:

You have no fonts installed that match the names in the array with the variable fontNames.

 

Regards,
Uwe Laubender

( ACP )

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Sep 30, 2020 Sep 30, 2020

Copy link to clipboard

Copied

I do have all those fonts 😞

I'm saving this as a .jsx file in my Scripts Panel, this is correct right?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Sep 30, 2020 Sep 30, 2020

Copy link to clipboard

Copied

Are you selected somewhere into a text frame with your text tool? 

Do you get any warning or error messages? 

 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Oct 01, 2020 Oct 01, 2020

Copy link to clipboard

Copied

LATEST

Yes, I have tried putting the cursor in the text frame, selecting text, and just selecting the text frame.

Unfortunately I do not get any error messages. I will attach a screen recording of what I am doing... maybe there is something I am doing very wrong.

 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines