LoginSignup
0
0

More than 3 years have passed since last update.

画像をグラフィックシンボルに変換.jsfl

Last updated at Posted at 2012-12-26

ライブラリ上の画像をグラフィックシンボルに変換するJSFLコマンドです。

画像左上を原点にしたグラフィックシンボルを生成する場合はこちらのコマンドを使用してください。

/**
 * ビットマップからグラフィックシンボルを生成するjsfl
 *
 * 使用方法 ライブラリでビットマップオブジェクトを選択してコマンドを実行する
 * 原点は左上端で固定
 *
 * @since 2009.09.24
 **/

var doc;
var lib;

main();

function main() {
  var doc = fl.getDocumentDOM();
  if (doc) {
    lib = doc.library; // ライブラリ
    var selItems = lib.getSelectedItems(); // 選択中のアイテム
    var num = selItems.length; // アイテム数

    if (num == 0) {
      alert("ライブラリのアイテムを選択してください");
      return;
    }

    //MCの生成---------------------

    for (var i = 0; i < num; i++) {
      var clipName = selItems[i].name + "_gra";
      var isCreated = lib.addNewItem("graphic", clipName);
      //if(!isCreated){ return; }

      lib.selectItem(clipName);
      lib.editItem();
      lib.selectItem(selItems[i].name);
      lib.addItemToDocument({ x: 0, y: 0 });
      doc.mouseClick({ x: 0, y: 0 }, false, true);
      doc.selection[0].x = 0;
      doc.selection[0].y = 0;
      doc.selection[0].width = doc.selection[0].hPixels;
      doc.selection[0].height = doc.selection[0].vPixels;
      doc.selection[0].x = 0;
      doc.selection[0].y = 0;
    }
  }
}

画像中央を原点にしたグラフィックシンボルを生成する場合はこちらのコマンドを使用してください。

/**
 * ビットマップから中央原点のグラフィックシンボルを生成するjsfl
 *
 * 使用方法 ライブラリでビットマップオブジェクトを選択してコマンドを実行する
 * 原点は中央で固定
 *
 * @since 2009.09.24
 */

var doc;
var lib;

main();

function main() {
  var doc = fl.getDocumentDOM();
  if (doc) {
    lib = doc.library; // ライブラリ
    var selItems = lib.getSelectedItems(); // 選択中のアイテム
    var num = selItems.length; // アイテム数

    if (num == 0) {
      alert("ライブラリのアイテムを選択してください");
      return;
    }

    //MCの生成---------------------

    for (var i = 0; i < num; i++) {
      var clipName = selItems[i].name + "_gra";
      var isCreated = lib.addNewItem("graphic", clipName);
      //if(!isCreated){ return; }

      lib.selectItem(clipName);
      lib.editItem();
      lib.selectItem(selItems[i].name);
      lib.addItemToDocument({ x: 0, y: 0 });
      doc.mouseClick({ x: 0, y: 0 }, false, true);
      doc.selection[0].x = 0;
      doc.selection[0].y = 0;
      doc.selection[0].width = doc.selection[0].hPixels;
      doc.selection[0].height = doc.selection[0].vPixels;
      doc.selection[0].x = -doc.selection[0].hPixels / 2;
      doc.selection[0].y = -doc.selection[0].vPixels / 2;
    }
  }
}
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