Unable to catch error that occurs when exporting empty artboard to PSD
en_US
When exporting Illustrator artboards to PSD using ExtendScript's exportFile, if the artboard does not contain valid PageItems, an error occurs and two alerts are displayed.
![error1.png](error1.png)
![error2.png](error2.png)
The problem is that this error cannot be caught by a try syntax. It will stop the batch process with alerts.
Also, if app.userInteractionLevel = UserInteractionLevel.DONTDISPLAYALERTS
is used to prevent the alert, it is not possible to provide detailed information to the script user as to why the artboard was not exported.
Ideally, the design should be changed so that the error can be caught, or even an empty artboard can be exported.
Steps to reproduce
- open the attached file empty_artboard.ai in Illustrator
- execute the script in the Script to execute section or the attached file psd_export.txt (please change the extension to jsx beforehand)
Expected result
Errors will be caught and an alert "Caught error" will appear, then safely exit.
Actual result
The error penetrates try syntax and the alert is displayed twice. The contents are as follows:
1. Empty artboard(s) were not exported.
2. The operation cannot be completed because of an unknown error. [!SEL]
The error 2 starts to occur in Illustrator 2022 and does not occur in older versions such as Illustrator 2021.
Workaround
- Use selectObjectsOnActiveArtboard, etc. to detect empty artboards by myself to avoid the error (to be precise, it is necessary to ignore isolated points and other PageItem that are ignored by the PSD export function by myself).
- Generate a Rectangle of the same size as the artboard without fill and stroke in advance and export it for avoid the error. An empty image will be successfully exported.
Environment
- macOS 12.7.3, 14.3.0(Apple Silicon)
- Illustrator 2019(23.1.1) to 2024(28.1.0)
Not sure when this error started, but it reproduces in Illustrator CS6 too.
Attached files
Script to execute
ja_JP
空のアートボードをPSDに書き出そうとしたとき起こるエラーをcatchできない
ExtendScriptのexportFileにてIllustratorのアートボードをPSDに書き出すとき、アートボードに有効なPageItemが含まれていないとエラーが起こり、2つの警告が出ます。
![error1.png](error1.png)
![error2.png](error2.png)
問題は、このエラーはtryで囲ってもcatchできないことです。バッチプロセスをアラートで止めてしまいます。
また、もしapp.userInteractionLevel = UserInteractionLevel.DONTDISPLAYALERTS
でアラートを出ないようにした場合、スクリプトのユーザーになぜアートボードが書き出されなかったか詳しい情報を提供することができません。
エラーをcatchできるようにするか、空のアートボードでも気にせず書き出すよう変更するのが理想的な設計です。
再現手順
- 添付ファイルempty_artboard.aiをIllustratorで開きます
- 実行するスクリプトセクションのスクリプトか、添付ファイルpsd_export.txtを実行します(事前に拡張子はjsxに変えておいてください)
期待する結果
エラーはcatchされ「Caught error」とアラートが出たあと安全に終了します。
実際の結果
エラーがtry構文を貫通し、アラートが2回表示されます。内容は次の通りです。
1. Empty artboard(s) were not exported.
2. The operation cannot complete because of an unknown error. [!SEL]
2のエラーはIllustrator 2022から出始めていて、それ以前のIllustrator 2021などでは発生しません。
回避策
- selectObjectsOnActiveArtboardなどを使い、空のアートボードを自力で検出してエラーを回避します(正確に言えば、孤立点などPSD書き出し機能に無視されるPageItemを、自力で無視する必要があります)
- アートボードと同じサイズの塗り・線なしのRectangleを事前に生成して書き出すことで、エラーを出ないようにできます。ただし、何もない画像が書き出しに成功します
環境
- macOS 12.7.3, 14.3.0(Apple Silicon)
- Illustrator 2019(23.1.1)〜2024(28.1.0)
このエラーがいつからあるのかわかりませんが、Illustrator CS6でも再現します。
添付したファイル
- error1.png
- error2.png
- empty_artboard.ai
- psd_export.txt
実行するスクリプト
(function() {
var doc = app.documents[0] ;
var psdOptions = new ExportOptionsPhotoshop() ;
try {
doc.exportFile(new File('~/Desktop/psd_empty_artboard_error.psd'), ExportType.PHOTOSHOP, psdOptions) ;
} catch(e) {
alert('Caught error') ;
}
})() ;
-
mer C commented
Noticed that I forgot to write Attached files and Script to execute in the English version. See the Japanese part or this comment.
### Attached files
* error1.png
* error2.png
* empty_artboard.ai
* psd_export.txt### Script to execute
```
(function() {
var doc = app.documents[0] ;
var psdOptions = new ExportOptionsPhotoshop() ;try {
doc.exportFile(new File('~/Desktop/psd_empty_artboard_error.psd'), ExportType.PHOTOSHOP, psdOptions) ;
} catch(e) {
alert('Caught error') ;
}
})() ;
```Moreover, I wrote Illustrator 2024(28.1.0), but it reproduces also with 28.2.0.