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

ExtendScript try/catch difference when script ran from ESTK and Illustrator

New Here ,
Apr 16, 2015 Apr 16, 2015

Hello,

I've written an ExtendScript for Illustrator using the ExtendScript ToolKit (ESTK).  This scripts works really well when running it in Illustrator from the ESTK (using the target application functionality).

However when I run it directly within Illustrator (by selecting it from the dropdown File > Scripts) I get a run time error.  Is this normal?  Should I expect differences when running the script in these two different ways?

The error is in this function...

```

function itemUsable (arr, item) {

    var usable = true;

    try {

        arr[item];

        usable = true;

    } catch(e) {

        $.global.alert(e);

        usable = false;

    }

    return usable;

}

```

The point of the code is to get around Illustrator's issue of throwing errors when accessing properties that don't always exist.  Ran from ESTK the try/catch statement catches the error "No such element" and then sets the function to return false.

When ran directly from Illustrator the error message fires but the try/catch doesn't seem to stop the script from exiting.

The only difference I can see is when running the script from ESTK the dropdown menu next to the application target dropdown is always (and has only the option) "main".  Running the script directly from Illustrator, when the error is thrown this dropdown option is set to the value "transient".

See this screenshot for an example what I mean

Screen Shot 2015-04-16 at 20.16.32.png

Any help would be much appreciated.

Thanks,

/t

TOPICS
Scripting
4.8K
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

correct answers 1 Correct answer

Mentor , Apr 20, 2015 Apr 20, 2015

Try adding $.level=0 at the beginning of the script or check out the last entry on the debug tab of the ESTK

Translate
Adobe
Mentor ,
Apr 20, 2015 Apr 20, 2015

Try adding $.level=0 at the beginning of the script or check out the last entry on the debug tab of the ESTK

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 20, 2015 Apr 20, 2015
LATEST

Thanks Trevor.

So it turns out that a script executed in Illustrator from ExtendScript has a different debug mode compared to a script that is opened directly by Illustrator.  Useful to know.

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