Skip to main content
Inspiring
April 3, 2026
Question

Intermittent 'PARM' Error When Accessing Text Font in Illustrator Script

  • April 3, 2026
  • 2 replies
  • 46 views

I’m brand new to scripting in Illustrator, I’m using VS Code and things are, sometimes, working . . . sort of.

I’m working from PDFs created from Word and have the script checking the font applied to the text frames, and if italic is in the name apply our italic font, if not apply our regular font. Seemed pretty straight forward.

But I was getting this error: an Illustrator error occurred: 1346458189 ('PARM')

On this line of code: txtFnt = tf.textRange.characterAttributes.textFont;

I began debugging and commenting out various lines. Eventually I had everything uncommented again with no changes to the actual code and it worked exactly as expected! No changes to the code and it stopped working again at the same spot.

I’ve seen a few posts with no resolution referring to this error.

Full script is at the bottom.

Does anyone have any hits as to WTF is happening?

Thank you,
Ken

 

//#target illustrator

 

function cleaupDoc() {

    if (app.documents.length > 0) {

        var doc = app.activeDocument;

        var textFrames = doc.textFrames;

        var count = 0;

        var txtFontReg = app.textFonts.getByName("MyFont-Regular");

        var txtFontItal = app.textFonts.getByName("MyFont-Italic");

        var txtFnt;

 

        // Loop backwards through text frames to avoid indexing issues after deletion

        for (var i = textFrames.length - 1; i >= 0; i--) {

            var tf = textFrames[i];

           

            // Check if frame is empty OR contains only whitespace characters

            // Replace '^\s*$' with '^$' if you ONLY want to delete truly empty objects

            if (tf.contents.match(/^\s*$/)) {

                tf.remove();

                count++;

             } else {

                txtFnt = tf.textRange.characterAttributes.textFont;

                if(txtFnt.name.indexOf('Italic') > 0) {

                    tf.textRange.characterAttributes.textFont = txtFontItal;

                }else{

                    tf.textRange.characterAttributes.textFont = txtFontReg;

                }

            }

        }

        alert(count + " empty text objects were deleted.");

    } else {

        alert("No active document found.");

    }

}

 

cleaupDoc();

 

    2 replies

    CarlosCanto
    Community Expert
    Community Expert
    April 3, 2026

    also if that doesn’t help, I would try collecting the empty text frames in an Array instead of deleting them. Then after changing the fonts I would start another loop to remove the empty frames in the array

    CarlosCanto
    Community Expert
    Community Expert
    April 3, 2026

    there doesn’t seem to be anything wrong with the script. I would just declare the tf variable outside of the loop

    var tf;

    for ....
    tf = textFrames[i];

     

    TNTGuysAuthor
    Inspiring
    April 3, 2026

    It was originally declared within the loop. In one of the unresolved posts I saw, someone mentioned that declaring WITHIN a loop seemed to sometimes cause the problem and suggested what I have here.

     

    Can’t hurt to try the array thing.

     

    Sure is maddening though, especially where it worked perfectly for a very short time.

     

    Oy!

     

    Thanks for posting.

    CarlosCanto
    Community Expert
    Community Expert
    April 4, 2026

    your script worked well here with my test file. If you can replicate the PARM error in a particular document, share the pdf file to test