Created
February 1, 2019 02:14
-
-
Save kysnrm/5459d176627be8cbf13839e33299dc10 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
//ダイアログの設定 | |
var dialog = new Window("dialog", "抵抗値の配列を入力する", [0, 0, 600, 90]); | |
dialog.add("statictext", [ | |
10, 20, 60, 40 | |
], "抵抗値"); | |
var length = dialog.add("edittext", [ | |
60, 15, 590, 40 | |
], "300"); //数の入力 | |
var btnCancel = dialog.add("button", [ | |
400, 50, 490, 80 | |
], "キャンセル", {name: 'cancel'}); //CANCEL | |
var btnOK = dialog.add("button", [ | |
500, 50, 590, 80 | |
], "実行", {name: 'ok'}); //OK | |
length.active = true; //テキストエリアをフォーカスする | |
//キャンセルの処理 | |
btnCancel.onClick = function() { | |
dialog.close(); | |
} | |
//OKの処理 | |
btnOK.onClick = function() { | |
{ | |
dialog.close(); | |
} //ダイアログを閉じる | |
var resistances = eval(length.text); | |
var doc = app.activeDocument; | |
var items = doc.pathItems; | |
for (var i = 0; i < resistances.length; i++) { | |
var resistance = resistances[i]; | |
var targetArtboard = doc.artboards[i]; | |
var targetArtboardRect = targetArtboard.artboardRect; | |
var sx1 = targetArtboardRect[0]; | |
var sy1 = targetArtboardRect[1]; | |
var sx2 = targetArtboardRect[2]; | |
var sy2 = targetArtboardRect[3]; | |
targetArtboard.name = resistance; | |
var splittedResistance = String(resistance).split(""); | |
var zeroCount = 0; | |
for (var j = 2; j < splittedResistance.length; j++) { | |
if (splittedResistance[j] === "0") { | |
zeroCount++; | |
} | |
} | |
var colorCode = [splittedResistance[0], splittedResistance[1], zeroCount, "金"]; | |
for (var j = 0; j < items.length; j++) { | |
var rect = items[j].geometricBounds; | |
var x1 = rect[0]; | |
var y1 = rect[1]; | |
var x2 = rect[2]; | |
var y2 = rect[3]; | |
if (x1 >= sx1 && x2 <= sx2 && y1 <= sy1 && y2 >= sy2) { | |
items[j].locked = true; | |
} | |
} | |
app.executeMenuCommand("unlockAll"); | |
for (var j = 0; j < colorCode.length; j++) { | |
var pathRef = doc.selection[j]; | |
pathRef.fillColor = doc.swatches.getByName(colorCode[j]).color; | |
} | |
} | |
} | |
dialog.center(); //ダイアログ表示位置をモニターの中心に移動 | |
dialog.show(); //作成したダイアログを表示 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment