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

Random Fonts Scripting

New Here ,
Apr 28, 2009 Apr 28, 2009

Hi everyone.

I'm workibng on a INDESIGN script which will help me to do what i want (how logical is this sentence...)

I'm working on a french translated version of a american comics and i'd like to keep his manua handwriting for the release.

To get a near perfect effect, i'd like to use different fonts, using some variants.

I more or less understand the way the script work, but i don't have the javascript understanding to get it works.

It would be something like that ( thanks to the Peter Spier solution) :

- Assign randomly  a number from 1 to n (n being the maximum fonts used)  to each character.

- Assign to each number a font.

- Maybe (if I cand) creating a panel asking which font use for the script.

I just don't know how i can do  RANDOM and ASSIGN.

(in fact looks like I don't know a thing about javascript)

If any of you got an idea.

Thanks

Ju

TOPICS
Scripting
1.9K
Translate
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 ,
Apr 28, 2009 Apr 28, 2009

Hi

I found this APPLE SCRIPTwhich do what i need.

on run
    local rnd, Nch
    tell application "TextEdit"
        if front document exists then
            if length of selection > 0 then
                set Nch to number of characters of selection
                repeat with i from 1 to Nch
                    set rnd to random number 3 from 0 to 3
                    if rnd = 0 then
                        set font of character i of selection to "juan1"
                    else if rnd = 1 then
                        set font of character i of selection to "juan2"
                    else if rnd = 2 then
                        set font of character i of selection to "juan3"
                    else
                        set font of character i of selection to "juan2"
                    end if
                end repeat
            else
                set Nch to number of characters of front document
                repeat with i from 1 to Nch
                    set rnd to random number 3 from 0 to 3
                    if rnd = 0 then
                        set font of character i of front document to "juan1"
                    else if rnd = 1 then
                        set font of character i of front document to "juan2"
                    else if rnd = 2 then
                        set font of character i of selection to "juan3"
                    else
                        set font of character i of front document to "juan2"
                    end if
                end repeat
            end if
        else
            error "Aucun document ouvert"
        end if
    end tell
end run

How could i transform it in JAVASCRIPT ??

Thank you

Julien

Translate
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 ,
Apr 28, 2009 Apr 28, 2009

Your example targets TextEdit, and InDesign is a bit more complicated. For example, in TextEdit you only have one 'text' -- InDesign has lots. The following script is a more-or-less literal translation, that assumes either you have some text selected, or the cursor is in the text thread that you want to work on.

if (app.selection[0].length < 1)
thetext = app.activeDocument.selection[0].parentStory;
else
thetext = app.selection[0];
for (var i=0; i<thetext.length; i++)
{
switch (Math.floor(Math.random()*3))
{
  case 0: thetext.characters.appliedFont = "Times\tBold"; break;
  case 1: thetext.characters.appliedFont = "Helvetica\tOblique"; break;
  case 2: thetext.characters.appliedFont = "Comic Sans MS\tRegular"; break;
}
}

The math stuff around random() returns an integer value from 0 to 2 (inclusive). That value is used in the switch cases -- which is way more efficient than endless 'if..else' constructions.

Notice the way the 'appliedFont' value is written: the '\t' is translated into a tab character on running, and that's how InDesign expects font names: "Font name [Tab] Style". Be sure to copy both font name and style name exactly, otherwise you will get errors.

Translate
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 ,
Apr 28, 2009 Apr 28, 2009

Hello Jongware

I will try that tomorrow.

Thanks a lot for the time you passed on it.

jU

Translate
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 ,
Apr 28, 2009 Apr 28, 2009

Jongware

Thanks a lot

Your script work and it will be helpfull.

Thanks a lot again.

To finish the scippt, i will try to had a dialog box asking wich font i will use ( i like to fight myself )

Thanks a lot again, you've just becomeone of my deities.

Thanks

Ju

Translate
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 ,
May 04, 2009 May 04, 2009

I was awake most of last night wondering how on earth I could create a word made of random typefaces. This could be one step in the right direction.

I have never scripted anything before. Where should I start?

Does this script only change the whole word?

Can you see a way that individual letters are assigned random fonts within the word?

Translate
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 ,
May 04, 2009 May 04, 2009

An older thread is "Random Font Script?" (see the 'More like this' box on your right).

I knew I had written something like that a while ago, and Peter Spier found it back at: http://forums.adobe.com/message/1281781#1281781

As for starting scripting, download the Scripting tutorial at www.adobe.com/devnet/indesign/pdfs/indesigncs4_scriptingtutorial.pdf (for CS4; look around the site for CS3). Read that and try the examples. If you get stuck, you can (almost) always ask here.

Translate
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 ,
May 04, 2009 May 04, 2009
LATEST

Thanks Jongware,

I had read that other post but missed the "shouldn't be too hard to add random fonts to the mix" bit the first time around. I'll have another look and put some time aside for Scripting 101.

I hope it isn't too nuts, I'm a designer and even CSS makes my head spin. But keen to give it a go.

Translate
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