-
Notifications
You must be signed in to change notification settings - Fork 0
/
MarginShapeMaker.jsx
255 lines (241 loc) · 12 KB
/
MarginShapeMaker.jsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
/*
==============================================================================================
MarginShapeMaker
Last Update:2018/03/07
https://github.com/yukichi0306/
==============================================================================================
*/
// 単位を px に変更
preferences.rulerUnits = Units.PIXELS;
//実行フラグ
flag = 1;
//ピクセルのある範囲 [left,top,right,bottom]
layObj = activeDocument.activeLayer.bounds;
x1 = layObj[0];
y1 = layObj[1];
x2 = layObj[2];
y2 = layObj[3];
selectW = x2 - x1;
selectH = y2 - y1;
//ダイアログを表示=================================================================================
uDlg = new Window('dialog','MarginShapeMaker',[0,0,280,200]);
uDlg.center();
uDlg.infoPnl = uDlg.add("panel",[30,6,250,6+60], "選択中のレイヤープロパティ");
uDlg.infoPnl.Text = uDlg.infoPnl.add("statictext",[0,16,220,16+24], "W:"+selectW+" H:"+selectH);
uDlg.infoPnl.justify = "center";
uDlg.infoPnl.Text.justify = "center";
uDlg.sText = uDlg.add("statictext",[36,84,36+56,84+24], "余白サイズ");
uDlg.sText = uDlg.add("statictext",[98,84,98+24,84+24], "X :");
uDlg.eText1 = uDlg.add("edittext",[124,84,124+30,84+24], 8);
uDlg.sText = uDlg.add("statictext",[156,84,156+24,84+24], "px");
uDlg.cBox = uDlg.add("checkbox",[188,98,188+24,98+24],"入力同期");
uDlg.sText = uDlg.add("statictext",[98,114,98+24,114+24], "Y :");
uDlg.eText2 = uDlg.add("edittext",[124,114,124+30,114+24], 8);
uDlg.sText = uDlg.add("statictext",[156,114,156+24,114+24], "px");
uDlg.cancelBtn = uDlg.add("button", [48,160,48+60,160+24], "キャンセル", {name: "cancel"});
uDlg.okBtn = uDlg.add("button",[168,160,168+60,160+24], "作成", { name:"ok"});
//チェックボックスをクリックした時
uDlg.cBox.onClick = function()
{
if(uDlg.cBox.value == true)
{
uDlg.eText2.text = uDlg.eText1.text;
}
}
//サイズ入力時の処理
uDlg.eText1.onChanging = function()
{
if(uDlg.cBox.value == true)
{
uDlg.eText2.text = uDlg.eText1.text;
}
}
uDlg.eText2.onChanging = function()
{
if(uDlg.cBox.value == true)
{
uDlg.eText1.text = uDlg.eText2.text;
}
}
//キャンセルボタンを押す時の処理
uDlg.cancelBtn.onClick = function ()
{
flag = 0;
uDlg.close();
}
uDlg.show();
//==============================================================================================
//半角整数かの判断
numVal1 = uDlg.eText1.text;
numVal2 = uDlg.eText2.text;
function isNumber (numVal1)
{
const pattern = /^[+,-]?([1-9]\d*|0)$/;
return pattern.test(numVal1);
}
function isNumber (numVal2)
{
const pattern = /^[+,-]?([1-9]\d*|0)$/;
return pattern.test(numVal2);
}
//入力された余白を元に、切抜き用シェイプの座標を計算
posL = x1 - parseInt(numVal1);
posT = y1 - parseInt(numVal2);
posR = x2 + parseInt(numVal1);
posB = y2 + parseInt(numVal2);
if ((flag == 1) && (isNumber (numVal1) == true) && (isNumber (numVal2) == true))
{
createShape();
moveLayer ();
}
else if ((isNumber (numVal1) == false) || (isNumber (numVal2) == false))
{
alert ("半角整数を入力してください。");
}
//シェイプの作成========================================================================================
function createShape()
{
var idMk = charIDToTypeID( "Mk " );
var desc12 = new ActionDescriptor();
var idnull = charIDToTypeID( "null" );
var ref2 = new ActionReference();
var idcontentLayer = stringIDToTypeID( "contentLayer" );
ref2.putClass( idcontentLayer );
desc12.putReference( idnull, ref2 );
var idUsng = charIDToTypeID( "Usng" );
var desc13 = new ActionDescriptor();
var idType = charIDToTypeID( "Type" );
var desc14 = new ActionDescriptor();
var idClr = charIDToTypeID( "Clr " );
//作成シェイプの色指定+++++++++++++++++++++++++++++
var desc15 = new ActionDescriptor();
var idRd = charIDToTypeID( "Rd " );
desc15.putDouble( idRd, 128 );
var idGrn = charIDToTypeID( "Grn " );
desc15.putDouble( idGrn, 128 );
var idBl = charIDToTypeID( "Bl " );
desc15.putDouble( idBl, 128 );
//+++++++++++++++++++++++++++++++++++++++++
var idRGBC = charIDToTypeID( "RGBC" );
desc14.putObject( idClr, idRGBC, desc15 );
var idsolidColorLayer = stringIDToTypeID( "solidColorLayer" );
desc13.putObject( idType, idsolidColorLayer, desc14 );
var idShp = charIDToTypeID( "Shp " );
var desc16 = new ActionDescriptor();
var idunitValueQuadVersion = stringIDToTypeID( "unitValueQuadVersion" );
desc16.putInteger( idunitValueQuadVersion, 1 );
var idTop = charIDToTypeID( "Top " );
var idPxl = charIDToTypeID( "#Pxl" );
desc16.putUnitDouble( idTop, idPxl, posT );//posT
var idLeft = charIDToTypeID( "Left" );
var idPxl = charIDToTypeID( "#Pxl" );
desc16.putUnitDouble( idLeft, idPxl, posL );//posL
var idBtom = charIDToTypeID( "Btom" );
var idPxl = charIDToTypeID( "#Pxl" );
desc16.putUnitDouble( idBtom, idPxl, posB );//posB
var idRght = charIDToTypeID( "Rght" );
var idPxl = charIDToTypeID( "#Pxl" );
desc16.putUnitDouble( idRght, idPxl, posR );//posR
var idtopRight = stringIDToTypeID( "topRight" );
var idPxl = charIDToTypeID( "#Pxl" );
desc16.putUnitDouble( idtopRight, idPxl, 0.000000 );
var idtopLeft = stringIDToTypeID( "topLeft" );
var idPxl = charIDToTypeID( "#Pxl" );
desc16.putUnitDouble( idtopLeft, idPxl, 0.000000 );
var idbottomLeft = stringIDToTypeID( "bottomLeft" );
var idPxl = charIDToTypeID( "#Pxl" );
desc16.putUnitDouble( idbottomLeft, idPxl, 0.000000 );
var idbottomRight = stringIDToTypeID( "bottomRight" );
var idPxl = charIDToTypeID( "#Pxl" );
desc16.putUnitDouble( idbottomRight, idPxl, 0.000000 );
var idRctn = charIDToTypeID( "Rctn" );
desc13.putObject( idShp, idRctn, desc16 );
var idstrokeStyle = stringIDToTypeID( "strokeStyle" );
var desc17 = new ActionDescriptor();
var idstrokeStyleVersion = stringIDToTypeID( "strokeStyleVersion" );
desc17.putInteger( idstrokeStyleVersion, 2 );
var idstrokeEnabled = stringIDToTypeID( "strokeEnabled" );
desc17.putBoolean( idstrokeEnabled, false );
var idfillEnabled = stringIDToTypeID( "fillEnabled" );
desc17.putBoolean( idfillEnabled, true );
var idstrokeStyleLineWidth = stringIDToTypeID( "strokeStyleLineWidth" );
var idPnt = charIDToTypeID( "#Pnt" );
desc17.putUnitDouble( idstrokeStyleLineWidth, idPnt, 4.000000 );
var idstrokeStyleLineDashOffset = stringIDToTypeID( "strokeStyleLineDashOffset" );
var idPnt = charIDToTypeID( "#Pnt" );
desc17.putUnitDouble( idstrokeStyleLineDashOffset, idPnt, 0.000000 );
var idstrokeStyleMiterLimit = stringIDToTypeID( "strokeStyleMiterLimit" );
desc17.putDouble( idstrokeStyleMiterLimit, 100.000000 );
var idstrokeStyleLineCapType = stringIDToTypeID( "strokeStyleLineCapType" );
var idstrokeStyleLineCapType = stringIDToTypeID( "strokeStyleLineCapType" );
var idstrokeStyleButtCap = stringIDToTypeID( "strokeStyleButtCap" );
desc17.putEnumerated( idstrokeStyleLineCapType, idstrokeStyleLineCapType, idstrokeStyleButtCap );
var idstrokeStyleLineJoinType = stringIDToTypeID( "strokeStyleLineJoinType" );
var idstrokeStyleLineJoinType = stringIDToTypeID( "strokeStyleLineJoinType" );
var idstrokeStyleMiterJoin = stringIDToTypeID( "strokeStyleMiterJoin" );
desc17.putEnumerated( idstrokeStyleLineJoinType, idstrokeStyleLineJoinType, idstrokeStyleMiterJoin );
var idstrokeStyleLineAlignment = stringIDToTypeID( "strokeStyleLineAlignment" );
var idstrokeStyleLineAlignment = stringIDToTypeID( "strokeStyleLineAlignment" );
var idstrokeStyleAlignInside = stringIDToTypeID( "strokeStyleAlignInside" );
desc17.putEnumerated( idstrokeStyleLineAlignment, idstrokeStyleLineAlignment, idstrokeStyleAlignInside );
var idstrokeStyleScaleLock = stringIDToTypeID( "strokeStyleScaleLock" );
desc17.putBoolean( idstrokeStyleScaleLock, false );
var idstrokeStyleStrokeAdjust = stringIDToTypeID( "strokeStyleStrokeAdjust" );
desc17.putBoolean( idstrokeStyleStrokeAdjust, false );
var idstrokeStyleLineDashSet = stringIDToTypeID( "strokeStyleLineDashSet" );
var list2 = new ActionList();
desc17.putList( idstrokeStyleLineDashSet, list2 );
var idstrokeStyleBlendMode = stringIDToTypeID( "strokeStyleBlendMode" );
var idBlnM = charIDToTypeID( "BlnM" );
var idNrml = charIDToTypeID( "Nrml" );
desc17.putEnumerated( idstrokeStyleBlendMode, idBlnM, idNrml );
var idstrokeStyleOpacity = stringIDToTypeID( "strokeStyleOpacity" );
var idPrc = charIDToTypeID( "#Prc" );
desc17.putUnitDouble( idstrokeStyleOpacity, idPrc, 100.000000 );
var idstrokeStyleContent = stringIDToTypeID( "strokeStyleContent" );
var desc18 = new ActionDescriptor();
var idClr = charIDToTypeID( "Clr " );
var desc19 = new ActionDescriptor();
var idRd = charIDToTypeID( "Rd " );
desc19.putDouble( idRd, 0.000000 );
var idGrn = charIDToTypeID( "Grn " );
desc19.putDouble( idGrn, 0.000000 );
var idBl = charIDToTypeID( "Bl " );
desc19.putDouble( idBl, 0.000000 );
var idRGBC = charIDToTypeID( "RGBC" );
desc18.putObject( idClr, idRGBC, desc19 );
var idsolidColorLayer = stringIDToTypeID( "solidColorLayer" );
desc17.putObject( idstrokeStyleContent, idsolidColorLayer, desc18 );
var idstrokeStyleResolution = stringIDToTypeID( "strokeStyleResolution" );
desc17.putDouble( idstrokeStyleResolution, 72.000000 );
var idstrokeStyle = stringIDToTypeID( "strokeStyle" );
desc13.putObject( idstrokeStyle, idstrokeStyle, desc17 );
var idcontentLayer = stringIDToTypeID( "contentLayer" );
desc12.putObject( idUsng, idcontentLayer, desc13 );
var idLyrI = charIDToTypeID( "LyrI" );
desc12.putInteger( idLyrI, 15 );
executeAction( idMk, desc12, DialogModes.NO );
}
//==========================================================================================================
//レイヤー順を選択レイヤーの一つ下に移動==============================================================================
function moveLayer()
{
var idmove = charIDToTypeID( "move" );
var desc6 = new ActionDescriptor();
var idnull = charIDToTypeID( "null" );
var ref3 = new ActionReference();
var idLyr = charIDToTypeID( "Lyr " );
var idOrdn = charIDToTypeID( "Ordn" );
var idTrgt = charIDToTypeID( "Trgt" );
ref3.putEnumerated( idLyr, idOrdn, idTrgt );
desc6.putReference( idnull, ref3 );
var idT = charIDToTypeID( "T " );
var ref4 = new ActionReference();
var idLyr = charIDToTypeID( "Lyr " );
var idOrdn = charIDToTypeID( "Ordn" );
var idPrvs = charIDToTypeID( "Prvs" );
ref4.putEnumerated( idLyr, idOrdn, idPrvs );
desc6.putReference( idT, ref4 );
executeAction( idmove, desc6, DialogModes.NO );
}
//==========================================================================================================