Skip to main content
Participant
March 24, 2011
Question

Batch font face and size change

  • March 24, 2011
  • 1 reply
  • 2209 views

Hi everybody,

I'm looking to create a batch action/script the will select and change the font face and size in a series of .eps files of barcodes.

I'm not sure if it's a scripting thing because I've never scripted before.

If anyone could point me in the right direction or tell me how to do it (action or script)  I'd be very grateful.

(Each image contains the barcode and three text elements, all Helvetica 24pt which I want to change to OCRB 18.5pt, on about 120 images)

Thanks chaps

This topic has been closed for replies.

1 reply

Inspiring
March 26, 2011

Try something like this

#target illustrator

app.userInteractionLevel = UserInteractionLevel.DONTDISPLAYALERTS;

/*************************************************************************************************************************************

Validate User Input.

*************************************************************************************************************************************/

function validateInput()

{

     if(dlg.input_panel.input_edt.text == "")

    {

            alert("Error, please define an input directory to convert.", "Error:");

            return -1;

    }

    return 0   

}

/*************************************************************************************************************************************

Define input Directory

*************************************************************************************************************************************/

function getInput()

{

    var input_folder = Folder.selectDialog( 'Select the directory where you wish to open the files: ', '' );

    if (input_folder != null)

    {

        dlg.input_panel.input_edt.text = input_folder.fsName;

    }

}

/*************************************************************************************************************************************

Open an eps file

*************************************************************************************************************************************/

function openFile(open_file)

{

    var open_options = new OpenOptions();

    open_options.updateLegacyText = true;

    app.open(open_file, DocumentColorSpace.RGB,open_options);

}

/*************************************************************************************************************************************

@Return return the index on the system for a font

*************************************************************************************************************************************/

function getIndex()

{

    var fontIndex = -1;

    for(var i=0; i<app.textFonts.length; i++)

    {

            if(app.textFonts.name == "ArialNarrow-Bold")

            {

                    fontIndex = i;

            }

    }

    return fontIndex;

}

/*************************************************************************************************************************************

Loop through text and change type

*************************************************************************************************************************************/

function changeText()

{

    var index_value = getIndex();

    if(index_value > 0)

    {

        var grayColour = new GrayColor();

        grayColour.gray = 100;

        for (var i = 0; i< app.activeDocument.textFrames.length; i++)

        {

                app.activeDocument.textFrames.textRange.characterAttributes.textFont = app.textFonts[index_value];

                app.activeDocument.textFrames.textRange.characterAttributes.kerningMethod = AutoKernType.AUTO;

                app.activeDocument.textFrames.textRange.characterAttributes.size = 10;

            app.activeDocument.textFrames.textRange.characterAttributes.fillColor = grayColour;

                for(var j=0; j<app.activeDocument.textFrames.textRange.characters.length; j++)

                {

                    app.activeDocument.textFrames.textRange.characters.characterAttributes.baselineShift = 0;

                    app.activeDocument.textFrames.textRange.characters.characterAttributes.leading = 12;

                    app.activeDocument.textFrames.textRange.characters.characterAttributes.tracking = 0

                    app.activeDocument.textFrames.textRange.characters.characterAttributes.rotation = 0;

                    app.activeDocument.textFrames.textRange.characters.characterAttributes.horizontalScale= 100;

                    app.activeDocument.textFrames.textRange.characters.characterAttributes.verticalScale= 100;

                }

            redraw();

        }

        for( var i=0 ; i < app.activeDocument.textFrames.length; i++ )

        {

            for ( p=0 ; p < app.activeDocument.textFrames.paragraphs.length ; p++ )

            {

                app.activeDocument.textFrames.paragraphs

.justification = Justification.CENTER;

                app.activeDocument.textFrames.paragraphs

.selection = true;

            }

        }

        alert("Finished");

    }

    else

    {

        alert("Arial Narrow Bold is not installed on your system!", "Error:");

    }

}

/*************************************************************************************************************************************

Save and close File

*************************************************************************************************************************************/

function saveFile()

{

    app.activeDocument.close(SaveOptions.SAVECHANGES);

}

/*************************************************************************************************************************************

Main

*************************************************************************************************************************************/

function main()

{

    if(validateInput() == -1)

        return;

    var input_folder = new Folder(dlg.input_panel.input_edt.text);

    var files_array = input_folder.getFiles( '*.eps' );

    logStatus ("c:\\boarder_report.csv", "SIZE", "FILE NAME", "STATUS");

    logStatus ("c:\\boarder_report.csv", "SIZE", "FILE NAME", "STATUS");

    for(var i = 0; i <= files_array.length; i++)

    {

openFile(new File(files_array));

changeText()

        saveFile();

    }

    alert("Done Processing Files");

}

/*************************************************************************************************************************************

Create GUI

*************************************************************************************************************************************/

function buildGUI()

{

    dlg = new Window('dialog', 'RPSTL Add Box Tool', [100,100,480,225]);

    dlg.input_panel = dlg.add('panel',[5,10,375,80], 'Input Directory');

    dlg.input_panel.input_txt = dlg.input_panel.add('statictext', [10,12,125,25], 'Browse for Input  Directory:');

    dlg.input_panel.input_btn = dlg.input_panel.add('button', [10,30,110,50], 'Browse');

    dlg.input_panel.input_edt = dlg.input_panel.add('edittext', [120,30,350,50], '');

    dlg.start_btn = dlg.add('button', [250,85,375,110], 'Start Conversion');

    dlg.input_panel.input_btn.onClick = getInput;

    dlg.start_btn.onClick = main;

    dlg.show();

}

buildGUI();