Last active
December 17, 2015 15:19
-
-
Save thinkAmi/5631045 to your computer and use it in GitHub Desktop.
グループ化されたオブジェクトを新レイヤーへ複数回コピー・配置する、Illustrator向けのJavaScript。ブログはこちら→ http://d.hatena.ne.jp/thinkAmi/20130523/1369257947
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// グループ化されたオブジェクトを新レイヤーへ複数回コピー・配置する | |
// 方法) 列方向に、ひとつの元絵をコピー・グループ化したあと、行方向に、そのグループをコピーする | |
(function(){ | |
const ROW_COUNT = 11; | |
const COLUMN_COUNT = 4; | |
const SPACE_LEFT_MM = 7.4; | |
const SPACE_LEFT_PT = toPT(SPACE_LEFT_MM) | |
const A4_HEIGHT_MM = 297; | |
const SPACE_TOP_MM = 9.4; | |
const LABEL_TOP_MM = A4_HEIGHT_MM - SPACE_TOP_MM; | |
const LABEL_TOP_PT = toPT(LABEL_TOP_MM); | |
const LABEL_WIDTH_MM = 48.3; | |
const LABEL_WIDTH_PT = toPT(LABEL_WIDTH_MM); | |
const LABEL_HEIGHT_MM = 25.48; | |
const LABEL_HEIGHT_PT = toPT(LABEL_HEIGHT_MM); | |
var newLayer = app.activeDocument.layers.add(); | |
var baseItem = app.activeDocument.layers[1].groupItems[0].duplicate(); | |
baseItem.moveToEnd(newLayer); | |
baseItem.position = [SPACE_LEFT_PT, LABEL_TOP_PT]; | |
var baseGroup = app.activeDocument.groupItems.add(); | |
baseItem.move(baseGroup, ElementPlacement.PLACEATEND); | |
var leftPosition = SPACE_LEFT_PT; | |
for (var i=0; i < COLUMN_COUNT - 1; i++) | |
{ | |
var item = baseItem.duplicate(); | |
leftPosition += LABEL_WIDTH_PT; | |
item.position = [leftPosition, LABEL_TOP_PT]; | |
} | |
var heightPosition = LABEL_TOP_PT; | |
for (var i=0; i < ROW_COUNT - 1; i++) | |
{ | |
var group = baseGroup.duplicate(); | |
heightPosition -= LABEL_HEIGHT_PT; | |
group.position = [SPACE_LEFT_PT, heightPosition]; | |
} | |
})(); | |
// ミリメートル単位から、pt単位へと変換する | |
// 物理的な紙の縦横はミリメートルで指定したほうが分かりやすいため | |
function toPT(mm){ | |
const coefficient = 72 / 25.4; | |
const unit = 10000000; | |
return Math.round(mm * coefficient * unit) / unit; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment