Illustratorのスクリプトで、一部の領域のみをエクスポートする方法が見つからず試行錯誤したので書いておきます。
エクスポートする
まず、Illustratorでエクスポートするには?
Illustrator Scripting Referenceを開き、 export で検索します。
Document methodsの項に、 exportFile を発見。
exportFile(exportFile, exportFormat [,options])
Exports the document to the specified file using one of the predefined export file formats. The appropriate file extension is automatically appended to the file name, except for Photoshop® documents. For these, you must include the file extension (PSD) in the file specification.
第2引数でフォーマットを、第3引数でその他のオプションを指定するようです。
オプションは、同じく「 export 」で検索すると出てくる「ExportOptions〜」クラスのインスタンスを渡します。
ExportOptionsAutoCADExportOptionsFlashExportOptionsGIFExportOptionsJPEGExportOptionsPhotoshopExportOptionsPNG8ExportOptionsPNG24ExportOptionsSVGExportOptionsTIFF今回はPNG形式で出力したかったので、 ExportOptionsPNG24 の項を参照します。
調べる前は、「 options.exportRect みたいな感じで、エクスポート領域を指定できるんだろう」と思っていたのですが…見つからない。
領域に関する設定は、「 artBoardClipping 」のみ。
artBoardClipping
If true, the exported image be clipped to the art board. Default: false
これを true に設定すると、アートボードの範囲にクリップされるようです。
つまり、アートボードの大きさをエクスポートしたい領域に合わせれば、指定した領域のエクスポートが実現できるはず。
同様にリファレンスを辿りながら、こんな感じでアートボードの領域が取得できました。
var doc = app.activeDocument;
var artboards = doc.artboards;
var artboard = artboards[artboards.getActiveArtboardIndex()];
alert(artboard.artboardRect);
この artboardRect を変更することで、アートボードのサイズが変更できます。
var doc = app.activeDocument;
var artboards = doc.artboards;
var artboard = artboards[artboards.getActiveArtboardIndex()];
artboard.artboardRect = [0, 0, 200, -300];アートボードのサイズを変更しっぱなしでは、ユーザが困ってしまいます。もとに戻してあげるまでがスクリプトの仕事です。 副作用なく使えるように、関数としてまとめておきましょう。
function exportPng24(document, rect, file) {
    var artboards = document.artboards;
    var artboard = artboards[artboards.getActiveArtboardIndex()];
    
    // アートボードの領域を覚えておく (あとで元に戻す)
    var prevRect = artboard.artboardRect;
    
    // アートボードをエクスポートしたい領域に変更する
    artboard.artboardRect = rect;
    
    // アートボード領域でクリップするように設定
    var options = new ExportOptionsPNG24();
    options.artBoardClipping = true;
    
    // エクスポート!
    document.exportFile(file, ExportType.PNG24, options);
    
    // アートボードの領域を元に戻す
    artboard.artboardRect = prevRect;
}
var document = app.activeDocument;
var file = new File('~/Desktop/hoge.png');
exportPng24(document, [0, 0, 200, -300], file);前の例では領域を直接指定しましたが、選択オブジェクトに合わせる場合は Document#fitArtboardToSelectedArt が使えます。
オブジェクトの選択は、 someObject.selected = true; です。