-
Notifications
You must be signed in to change notification settings - Fork 0
/
Serial-Renamer.jsx
54 lines (40 loc) · 1.55 KB
/
Serial-Renamer.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
function buildUI(thisObj){
var main_wnd;
if(thisObj instanceof Panel){
main_wnd = thisObj ;
}else{
main_wnd = new Window("palette", "Serial-Renamer", undefined, {resizeable : true});
}
main_wnd.preferredSize = [200,200]
var input_text = main_wnd.add("edittext", undefined, "",{multiline : true});
input_text.alignment = ["fill","fill"];
var check_is = main_wnd.add("checkbox", [30, 10, 220, 30],"Ignore space (recommend)");
check_is.value = true
check_is.alignment = ["fill","bottom"];
var ok_btn = main_wnd.add("button", undefined, "OK");
ok_btn.alignment = ["fill","bottom"];
main_wnd.layout.layout();
ok_btn.onClick = function(){
var text_data = input_text.text.replace(/\r?\n/g, '')
var activeItem = app.project.activeItem;
if (check_is.value == true) text_data = text_data.replace(/\s+/g, "");
if(activeItem){
if(activeItem.selectedLayers.length <= text_data.length){
for (var i = 0; i <= Number(activeItem.selectedLayers.length); i++) activeItem.selectedLayers[i].name = text_data.charAt(i);
}else{
alert("The number of characters is greater than the number of layers selected.");
}
}else{
alert("The active item is not selected.");
}
}
main_wnd.onResize = function(){
main_wnd.layout.resize();
}
return main_wnd;
}
var toolspanel = buildUI (this);
if(!(toolspanel instanceof Panel)){
toolspanel.center();
toolspanel.show();
}