2
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

[Illustrator_script]選択オブジェクトの座標を取得する

Last updated at Posted at 2018-11-13

##やりたこと
選択したオブジェクトの座標をミリ単位で取得したい。

##やったこと

実際のソースコードです。

getObjBounds.jsx
var doc = app.activeDocument;
var board = doc.artBoards;
var sel = doc.selection;
var rect = sel[0].visibleBounds;

alert(rect[0] + "," + rect[1] + "," + rect[2] + "," + rect[3]);

このままではPt単位で値を取得してしまいますので少し手を加えます。
合わせて小数点第1位以下も四捨五入してしまいます。

getObjBounds.jsx
var doc = app.activeDocument;
var board = doc.artBoards;
var sel = doc.selection;
var rect = sel[0].visibleBounds;
var convMilli = 1 / (25.4 / 72);

for (var i = 0 ; i < rect.length; i++) {
    rect[i]  = Math.round(rect[i] * convMilli * 10) / 10;
}

alert(rect[0] + "," + rect[1] + "," + rect[2] + "," + rect[3]);

##解説
var convMilli = 1 / (25.4 / 72);
1ポイント = 1インチ ÷ 72
1インチ = 25.4mm
から計算。

2
2
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
2
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?