/
AddGuidesEx.jsx
191 lines (159 loc) · 6.55 KB
/
AddGuidesEx.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
/*==============================================================================
File Name: AddGuidesEx.jsx
Title: Add Guides EX
Version: 1.0.0
Author: Phize
Author URI: http://phize.net
http://dxd8.com
Copyright(C) 2009 Phize
==============================================================================*/
#target photoshop
app.bringToFront();
// Add Guides EX
function addGuidesEx() {
// ----------------------------------------
// Locale
// 'en': English
// 'ja': 日本語
// ----------------------------------------
// $.locale = 'en';
// ----------------------------------------
// Default values
// ----------------------------------------
var position = 0; // Default position
var width = 32; // Default width
var gap = 0; // Default gap
var number = 1; // Default number
// ----------------------------------------
// Texts for localize
// ----------------------------------------
var i18n = {
title: { en: 'Add Guides EX', ja: 'Add Guides EX' },
direction: { en: 'Direction', ja: '方向' },
horizontal: { en: 'Horizontal', ja: '水平方向' },
vertical: { en: 'Vertical', ja: '垂直方向' },
position: { en: 'Position', ja: '位置' },
width: { en: 'Width', ja: '幅' },
gap: { en: 'Gap', ja: '間隔' },
number: { en: 'Number', ja: '数' },
unit: { en: 'Unit', ja: '単位' },
ok: { en: 'OK', ja: 'OK' },
cancel: { en: 'Cancel', ja: 'キャンセル' }
};
// ----------------------------------------
// Dialog resource object
// ----------------------------------------
var ui =
"dialog { \
text: '" + localize(i18n.title) + "', \
orientation: 'row', \
gVariable: Group { \
orientation: 'column', \
alignment: 'fill', \
pDirection: Panel { \
alignChildren: 'left', \
text: '" + localize(i18n.direction) + "', \
horizontal: RadioButton { text: '" + localize(i18n.horizontal) + "' }, \
vertical: RadioButton { text: '" + localize(i18n.vertical) + "', value: true }, \
}, \
gPosition: Group { \
orientation: 'row', \
alignment: 'right', \
label: StaticText { text: '" + localize(i18n.position) + ":' }, \
position: EditText { text: '" + position + "', preferredSize: [ 48, 20 ] }\
}, \
gWidth: Group { \
orientation: 'row', \
alignment: 'right', \
label: StaticText { text: '" + localize(i18n.width) + ":' }, \
width: EditText { text: '" + width + "', preferredSize: [ 48, 20 ] }\
}, \
gGap: Group { \
orientation: 'row', \
alignment: 'right', \
label: StaticText { text: '" + localize(i18n.gap) + ":' }, \
gap: EditText { text: '" + gap + "', preferredSize: [ 48, 20 ] }\
}, \
gNumber: Group { \
orientation: 'row', \
alignment: 'right', \
label: StaticText { text: '" + localize(i18n.number) + ":' }, \
number: EditText { text: '" + number + "', preferredSize: [ 48, 20 ] }\
}, \
}, \
gButton: Group { \
orientation: 'column', \
alignment: 'fill', \
ok: Button { \
text: '" + localize(i18n.ok) + "', \
properties: { name: 'ok' }, \
}, \
cancelBtn: Button { \
text: '" + localize(i18n.cancel) + "', \
properties: { name: 'cancel' }, \
}, \
} \
}";
// ----------------------------------------
// Methods
// ----------------------------------------
function addGuide(offset, orientation) {
var id1 = charIDToTypeID('Mk ');
var desc1 = new ActionDescriptor();
var id2 = charIDToTypeID('Nw ');
var desc2 = new ActionDescriptor();
var id3 = charIDToTypeID('Pstn');
var id4 = charIDToTypeID('#Rlt');
desc2.putUnitDouble(id3, id4, offset);
var id5 = charIDToTypeID('Ornt');
var id6 = charIDToTypeID('Ornt');
var id7 = charIDToTypeID(orientation);
desc2.putEnumerated(id5, id6, id7);
var id8 = charIDToTypeID('Gd ');
desc1.putObject(id2, id8, desc2);
executeAction(id1, desc1, DialogModes.NO);
}
function ok() {
var direction = dlg.gVariable.pDirection.vertical.value ? 'Vrtc' : 'Hrzn';
var position = parseInt(dlg.gVariable.gPosition.position.text);
var width = parseInt(dlg.gVariable.gWidth.width.text);
var gap = parseInt(dlg.gVariable.gGap.gap.text);
var number = parseInt(dlg.gVariable.gNumber.number.text);
for (var i = 0; i < number; i ++) {
if (gap > 0 && i > 0) {
addGuide(position + width * i + gap * (i - 1), direction);
addGuide(position + width * i + gap * i, direction);
} else {
addGuide(position + width * i, direction);
}
}
dlg.close();
}
function cancel() {
dlg.close();
}
// ----------------------------------------
// Main
// ----------------------------------------
var dlg = new Window(ui);
dlg.gButton.ok.onClick = ok;
dlg.gButton.cancelBtn.onClick = cancel;
dlg.center();
dlg.show();
}
if (app.documents.length > 0) {
// Store default setting
var _rulerUnits = app.preferences.Units;
var _typeUnits = app.preferences.typeUnits;
var _displayDialogs = app.displayDialogs;
// Set setting for script
app.preferences.rulerUnits = Units.PIXELS;
app.preferences.typeUnits = TypeUnits.PIXELS;
app.displayDialogs = DialogModes.NO;
// Show dialog
addGuidesEx();
// Restore default setting
app.preferences.Units = _rulerUnits;
app.preferences.typeUnits = _typeUnits;
app.displayDialogs = _displayDialogs;
}