Quantcast
Channel: Adobe Community : Popular Discussions - Illustrator Scripting
Viewing all articles
Browse latest Browse all 12845

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

$
0
0

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


Viewing all articles
Browse latest Browse all 12845

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>