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

Exception has been thrown by the target of an invocation. Error 1220: Illegal Argument

Community Beginner ,
Jun 07, 2022 Jun 07, 2022

Copy link to clipboard

Copied

While running a JavaScript file from C#/COM, I will occasionally receive the error "Exception has been thrown by the target of an invocation. Error 1220: Illegal Argument", the error goes on to show the line # of the offending javascript, but this doesn't happen every time, and usually within a few retries it will pass.

 

What might cause this? Here is the javascript in question, and usually the error reports that line #8 is the offender "if (frames[x].textRange.characterAttributes.textFont != null) {"

var frames = app.activeDocument.textFrames;
var len = frames.length;

for (var x = 0; x < len; x++) {
    if (frames[x] != null) {
        if (frames[x].textRange != null) {
            if (frames[x].textRange.characterAttributes != null) {
                if (frames[x].textRange.characterAttributes.textFont != null) {
                    if (frames[x].textRange.characterAttributes.textFont.name != null) {
                        if (frames[x].textRange.characterAttributes.textFont.name.toLowerCase().indexOf("avenir") >= 0) {
                            if (frames[x].textRange.characterAttributes.textFont.name == "Avenir-BlackOblique") {
                                frames[x].textRange.characterAttributes.textFont = textFonts.getByName("ProximaNova-Bold");
                            } else if (frames[x].textRange.characterAttributes.textFont.name == "Avenir-Medium") {
                                frames[x].textRange.characterAttributes.textFont = textFonts.getByName("ProximaNova-Medium");
                            }
                        }
                    }
                }
            }
        }
    }
}

var avenirFonts = "";

for (var x = 0; x < len; x++) {
    if (frames[x] != null) {
        if (frames[x].textRange != null) {
            if (frames[x].textRange.characterAttributes != null) {
                if (frames[x].textRange.characterAttributes.textFont != null) {
                    if (frames[x].textRange.characterAttributes.textFont.name != null) {
                        if (frames[x].textRange.characterAttributes.textFont.name.toLowerCase().indexOf("avenir") >= 0 && avenirFonts.indexOf(frames[x].textRange.characterAttributes.textFont.name) < 0) {
                            avenirFonts = avenirFonts + frames[x].textRange.characterAttributes.textFont.name + "\n";
                        }
                    }
                }
            }
        }
    }
}

if (avenirFonts.length > 0) {
    throw "Found Avenir Fonts: " + avenirFonts;
}

  The purpose of this script is to replace the Apple Avenir fonts to a windows available font, and it will work even if I receive an error after a few retries. We have automation built out to create AI templates from source files ever 5 minutes to assist our design team.

TOPICS
Scripting , SDK

Views

346

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
Adobe
Community Beginner ,
Jun 07, 2022 Jun 07, 2022

Copy link to clipboard

Copied

"TryFixIllustratorFonts: Exception has been thrown by the target of an invocation. Error 45: Object is invalid.Line: 5-> if (frames[x] != null) {"

I've also seen this error. Is there a place to look up the error codes for 1220 and 45?

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
Guide ,
Jun 07, 2022 Jun 07, 2022

Copy link to clipboard

Copied

LATEST

The "Illegal Argument" error could be caused by "textFont" when the string is empty. Furthermore, when an object is absent, Illustrator throws an error (no such element) as soon as the object expression is evaluated. So there is no point testing it with "null". Try using "try...catch" instead of conditionals.

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