Amazonで商品を見るセール会場へ

Photoshopスクリプト(jsx)│選択したグループを反転コピーする方法

Photoshopで選択したグループを反転コピーするスクリプトを紹介します。

左右対称のデザインやLive2Dの素材作成に役立ちます。

目次

スクリプトを使用するメリット

  • 選択したグループを反転コピーできる
  • 左右対称のパーツを効率よく作成できる
  • ショートカットを設定すればキー操作で実行できる

スクリプトで選択グループを反転コピーする手順

このスクリプトを使うと、選択したグループをすばやく反転コピーできます。

STEP.1 スクリプトを保存する

  1. 下記のコードをテキストエディタなどに貼り付けて保存します。

Photoshopのほかの操作は、まとめからご覧いただけます。

CGM_ReverseCopyGroup.jsx

function ReverseCopy() {
  cTID = function (s) {
    return app.charIDToTypeID(s);
  };
  sTID = function (s) {
    return app.stringIDToTypeID(s);
  };  //グループの複製
  function step1(enabled, withDialog) {
    if (enabled != undefined && !enabled) return;
    var dialogMode = (withDialog ? DialogModes.ALL : DialogModes.NO);
    var desc1 = new ActionDescriptor();
    var ref1 = new ActionReference();
    ref1.putEnumerated(cTID('Lyr '), cTID('Ordn'), cTID('Trgt'));
    desc1.putReference(cTID('null'), ref1);
    var desc2 = new ActionDescriptor();
    desc2.putUnitDouble(cTID('Hrzn'), cTID('#Prc'), 0);
    desc2.putUnitDouble(cTID('Vrtc'), cTID('#Prc'), 0);
    desc1.putObject(cTID('T   '), cTID('Ofst'), desc2);
    executeAction(sTID('copyEvent'), desc1, dialogMode);
  };  //レイヤーを結合
  function step2(enabled, withDialog) {
    if (enabled != undefined && !enabled) return;
    var dialogMode = (withDialog ? DialogModes.ALL : DialogModes.NO);
    executeAction(sTID('mergeLayersNew'), undefined, dialogMode);
  };
  //ドキュメント全体を範囲選択
  function step3(enabled, withDialog) {
    if (enabled != undefined && !enabled) return;
    var dialogMode = (withDialog ? DialogModes.ALL : DialogModes.NO);
    var desc1 = new ActionDescriptor();
    var ref1 = new ActionReference();
    ref1.putProperty(cTID('Chnl'), sTID("selection"));
    desc1.putReference(cTID('null'), ref1);
    desc1.putEnumerated(cTID('T   '), cTID('Ordn'), cTID('Al  '));
    executeAction(sTID('set'), desc1, dialogMode);
  };
  //変形で左右反転
  function step4(enabled, withDialog) {
    if (enabled != undefined && !enabled) return;
    var dialogMode = (withDialog ? DialogModes.ALL : DialogModes.NO);
    var desc1 = new ActionDescriptor();
    var ref1 = new ActionReference();
    ref1.putEnumerated(cTID('Lyr '), cTID('Ordn'), cTID('Trgt'));
    desc1.putReference(cTID('null'), ref1);
    desc1.putEnumerated(cTID('FTcs'), cTID('QCSt'), sTID("QCSAverage"));
    var desc2 = new ActionDescriptor();
    desc2.putUnitDouble(cTID('Hrzn'), cTID('#Prc'), 0);
    desc2.putUnitDouble(cTID('Vrtc'), cTID('#Prc'), 0);
    desc1.putObject(cTID('Ofst'), cTID('Ofst'), desc2);
    desc1.putUnitDouble(cTID('Wdth'), cTID('#Prc'), -100);
    desc1.putEnumerated(cTID('Intr'), cTID('Intp'), sTID("bicubicAutomatic"));
    executeAction(sTID('transform'), desc1, dialogMode);
  };
  //グループ化
  function step5(enabled, withDialog) {
    if (enabled != undefined && !enabled) return;
    var dialogMode = (withDialog ? DialogModes.ALL : DialogModes.NO);
    var desc1 = new ActionDescriptor();
    var ref1 = new ActionReference();
    ref1.putClass(sTID("layerSection"));
    desc1.putReference(cTID('null'), ref1);
    var ref2 = new ActionReference();
    ref2.putEnumerated(cTID('Lyr '), cTID('Ordn'), cTID('Trgt'));
    desc1.putReference(cTID('From'), ref2);
    var desc2 = new ActionDescriptor();
    desc1.putObject(cTID('Usng'), sTID("layerSection"), desc2);
    desc1.putInteger(sTID("layerSectionStart"), 678);
    desc1.putInteger(sTID("layerSectionEnd"), 679);
    desc1.putString(cTID('Nm  '), "Group");
    executeAction(sTID('make'), desc1, dialogMode);
  };
  //範囲選択を解除
  function step6(enabled, withDialog) {
    if (enabled != undefined && !enabled) return;
    var dialogMode = (withDialog ? DialogModes.ALL : DialogModes.NO);
    var desc1 = new ActionDescriptor();
    var ref1 = new ActionReference();
    ref1.putProperty(cTID('Chnl'), sTID("selection"));
    desc1.putReference(cTID('null'), ref1);
    desc1.putEnumerated(cTID('T   '), cTID('Ordn'), cTID('None'));
    executeAction(sTID('set'), desc1, dialogMode);
  };
  // グループを折りたたむ
  function step7(enabled, withDialog) {
    if (enabled != undefined && !enabled) return;
    var dialogMode = (withDialog ? DialogModes.ALL : DialogModes.NO);
    var desc1 = new ActionDescriptor();
    executeAction(sTID('collapseAllGroupsEvent'), desc1, dialogMode);
  };
  step1();
  step2();
  step3();
  step4();
  step5();
  step6();
  step7();
};
ReverseCopy.main = function () {
  ReverseCopy();
};

function CGM_ReverseCopyGroup() {
  try {
    ReverseCopy.main();
  } catch (e) {
    alert("グループを選択してください");
  }
}

var doc = activeDocument;
doc.suspendHistory("反転コピー", "CGM_ReverseCopyGroup();");
  1. CGM_ReverseCopyGroup.jsx を以下のフォルダに保存します。
C:\Program Files\Adobe\Adobe Photoshop CC\Presets\Scripts\
  1. Photoshopを再起動します。

STEP.2 スクリプトを実行する

  1. [ファイル] → [スクリプト] → [CGM_ReverseCopyGroup]を選択します。
  2. 選択したグループが反転コピーされます。

ショートカットを設定する方法

  1. [編集] → [キーボードショートカット]を開きます。
  2. 「ファイル」メニューからスクリプト(CGM_ReverseCopyGroup.jsx)を探します。
  3. 任意のキー(「F3」など)を割り当てます。
  4. 設定したショートカットキーを押すと、反転コピーが実行されます。

おまけ│アクションで反転コピーを作成する手順

① 左側を削除

  1. 新規レイヤーを作成
  2. [Alt + Shift + [ ] で下のレイヤーを追加選択
  3. [Ctrl + E] で統合
  4. [Ctrl + A] で全選択
  5. [選択範囲] → [選択範囲を変形] → ピボットを左中央 → Wを50%にして左側を選択
  6. [Delete] で左側を削除
  7. [Ctrl + D] で選択解除

② 右側を反転コピー

  1. [Ctrl + A] で全選択
  2. [Ctrl + J] でレイヤーを複製
  3. [Ctrl + A] で全選択
  4. [選択範囲] → [選択範囲を変形] → ピボットを右中央 → Wを50%にして右側を選択
  5. [Ctrl + T] で変形 → ピボットを左中央 → Wを-100%にして左側へ反転
  6. [Ctrl + E] で下のレイヤーと結合
  7. [Ctrl + D] で選択解除

この記事で紹介しているコードは、GitHubのMOTOKI-LLC/cg-method-codeにもまとめています。

シェイプや塗りを作る方法は、ほかにも書いています。

まとめ

  • 選択したグループを反転コピーできる
  • Live2Dのパーツ整理や左右対称のデザインに役立つ
  • ショートカットを設定するとさらに作業を効率化できる

作業時間を短縮したいときは、このスクリプトを活用してみてください。

次に学ぶ・作業環境を選ぶ

学習を続けたい方や、作業環境を整えたい方は、目的に合うガイドをご覧ください。

Photoshopのおすすめ書籍

動作要件とPCの確認項目

周辺機器の優先度

よかったらシェアしてね!
  • URLをコピーしました!
  • URLをコピーしました!
目次