0
0

Adobe Illustratorで印刷入稿前のチェックの効率化を図る自動化スクリプト

Last updated at Posted at 2024-07-04

はじめに

Adobe Illustratorで作業を自動化するためのスクリプト(JavaScript)を紹介します。このスクリプトは、印刷入稿前のチェックの効率化を図るために、以下の一連の操作を自動で実行します。

機能

このスクリプトは次の操作を自動で行います:

  1. 全てのレイヤーとオブジェクトのロック解除 - 編集が困難なロック状態を解除します。
  2. カラーモードの変換 - ドキュメントがRGBモードの場合、プリント基準のCMYKモードへ変換します。
  3. テキストのアウトライン化 - フォント依存の問題を避けるため、全てのテキストをアウトライン化します。
  4. リンクファイルの埋め込み - 外部リンクされている画像やデータをドキュメントに埋め込みます。
  5. ファイル名の自動改名 - ファイル名の末尾に「(CHK)」を追加し、バージョン管理を容易にします。
  6. AIとPDF形式での保存 - 編集可能なAIファイルと共有・印刷向けのPDFファイルの両方で保存します。

メリット

このスクリプトにより、以下のようなメリットがあります:

  • 時間の節約:複数の手動操作を一度に実行することで、時間を大幅に節約できます。
  • エラーの削減:手動での操作ミスを防ぎ、一貫した出力を保証します。
  • 作業の標準化:ファイルの保存形式や編集プロセスを標準化し、チーム間での共有が容易になります。
#target illustrator

function unlockAll(doc) {
    for (var i = 0; i < doc.layers.length; i++) {
        var layer = doc.layers[i];
        layer.locked = false;
        unlockItems(layer.pageItems);
    }
}

function unlockItems(items) {
    for (var i = 0; i < items.length; i++) {
        items[i].locked = false;
        if (items[i].typename == 'GroupItem') {
            unlockItems(items[i].pageItems);
        }
    }
}

function convertToCMYK(doc) {
    if (doc.documentColorSpace !== DocumentColorSpace.CMYK) {
        app.executeMenuCommand('doc-color-cmyk');
    }
}

function createOutlines(doc) {
    for (var i = 0; i < doc.textFrames.length; i++) {
        var textFrame = doc.textFrames[i];
        textFrame.createOutline();
    }
}

function embedLinkedFiles(doc) {
    var placedItems = doc.placedItems;
    for (var i = 0; i < placedItems.length; i++) {
        placedItems[i].embed();
    }
}

function appendToFilename(doc, extension) {
    var filePath = doc.fullName;
    var fileName = filePath.name.replace(/\.[^\.]+$/, '');
    var newFileName = fileName + ' (CHK).' + extension;
    var newPath = filePath.parent.fsName + '/' + newFileName;
    return new File(newPath);
}

function saveAsAI(doc, aiFile) {
    var aiSaveOptions = new IllustratorSaveOptions();
    aiSaveOptions.compatibility = Compatibility.ILLUSTRATOR17;
    aiSaveOptions.pdfCompatible = true;
    doc.saveAs(aiFile, aiSaveOptions);
}

function saveAsPDF(doc, pdfFile) {
    var pdfSaveOptions = new PDFSaveOptions();
    pdfSaveOptions.preserveEditability = false;
    doc.saveAs(pdfFile, pdfSaveOptions);
}

if (app.documents.length > 0) {
    var doc = app.activeDocument;

    unlockAll(doc);
    convertToCMYK(doc);
    createOutlines(doc);
    embedLinkedFiles(doc);

    var aiFile = appendToFilename(doc, 'ai');
    var pdfFile = appendToFilename(doc, 'pdf');
    saveAsAI(doc, aiFile);
    saveAsPDF(doc, pdfFile);

    alert('Script executed successfully. Saved as AI: ' + aiFile.fsName + ' and as PDF: ' + pdfFile.fsName);
} else {
    alert('No document is open.');
}

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0