-
Notifications
You must be signed in to change notification settings - Fork 0
/
usefulFunctions.jsx
119 lines (116 loc) · 2.93 KB
/
usefulFunctions.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
#include "y_JSExtensions.jsx";
function sortNumber(a,b){
return a - b;
}
function pad(n,i){ //pad n with ceroes up to i places.
if (String(n).length>=i){
return String(n)
}else{
dif = i- (String(n)).length;
padding = "";
for (p=0;p<dif;p++){
padding = padding+"0"
}
return padding+String(n)
}
}
function yUniStr(str){
if (app.project.activeItem != null) {
myLayers = app.project.activeItem.layers;
//myLayerNames = [];
nameMatches = [];
for (i=1;i<=myLayers.length;i++){
if(getBaseName(myLayers[i].name) == getBaseName(str)){
nameMatches.push(getN(myLayers[i].name))
}
}
newN = getFirstGap(nameMatches);
if(nameMatches.length == 0 | (newN==0)){
return str
}else{
return str+' '+newN
}
}else{
alert('E01 : No Comp is ACTIVE')
}
}
function getN(str){
lastChunk = str.substr(str.lastIndexOf(' '),str.length);
if(lastChunk == parseInt(lastChunk)){
return parseInt(lastChunk);
}else{
return 0;
};
}
function getBaseName(str){
lastChunk = str.substr(str.lastIndexOf(' '),str.length);
if(lastChunk == parseInt(lastChunk)){
return str.substr(0,str.lastIndexOf(' '));
}else{
return str;
};
}
function getFirstGap(array){
length = array.length
array.sort(function sortNumber(a,b){return a-b})
max = array[array.length-1]
for (n=0;n<=max;n++){
entry = array.getOne(n);
if (entry == -1){
return n
}
}
return max+1
return array[0];
}
function yReplace(inputSTR,replaceSTR,replacementSTR){
tmpArray = inputSTR.split(replaceSTR);
tmpSTR = '';
for(i=0;i<tmpArray.length;i++){
tmpSTR = tmpSTR+tmpArray[i]
if(i<tmpArray.length-1){
tmpSTR = tmpSTR+replacementSTR;
}
}
return tmpSTR;
}
function genStamp(args){
d = new Date();
//alert(d.getMonth());
y = String(d.getFullYear()).substring(2,4);
m = pad(d.getMonth()+1,2);
d = pad(d.getUTCDate(),2);
str = String(m)+String(d)+String(y);
return str
}
function mergeMultiLine(_str){
var re = new RegExp('[\n\r]');
_lines = _str.split(re);
newStr = '';
if(_lines.length>1){
for(L=0;L<_lines.length;L++){
alert(_lines[L]);
if(L==_lines.length-1||_lines[L]==''){
dash = '';
}else{
dash = '.';
}
if(_lines[L]!=''){
newStr = newStr+_lines[L]+dash;
}else{
newStr = newStr;
}
}
}else{
newStr = _str;
}
return newStr;
}
function yFactor(n,f){
if((typeof(n)=='number'&&typeof(f)=='number')&&(n>f)){
value = n - (n%f);
return(value);
}else{
alert('error');
}
}