Copy link to clipboard
Copied
The same name of the channel, is the same pattern. How to keep different channel names, and delete redundant channels with the same name
all channelļ¼1,4,2,1,2,3,1,3,2,4------->channel:1,4,2,3
Hi Roychen,
Hope this will help... š
var dup=[];
if(app.documents.length>0){
var docRef = app.activeDocument;
var mychan = docRef.channels;
var l=mychan.length;
while(l--) {
var mychans=mychan[l].name;
if(dup.toString().indexOf (mychans)==-1){
dup.push(mychan[l].name);
}
else{mychan[l].remove();}
}
}
-yajiv
Copy link to clipboard
Copied
Hi Roychen,
Hope this will help... š
var dup=[];
if(app.documents.length>0){
var docRef = app.activeDocument;
var mychan = docRef.channels;
var l=mychan.length;
while(l--) {
var mychans=mychan[l].name;
if(dup.toString().indexOf (mychans)==-1){
dup.push(mychan[l].name);
}
else{mychan[l].remove();}
}
}
-yajiv
Copy link to clipboard
Copied
hi natrev
very good....thx....
Copy link to clipboard
Copied
hi natrev..
have some question,if all channel is 1,2,3,4,4a,3a,1a,2a,1,2 ,run javscript ,result:1a,2a,3a,4a,1,2...lose 3,4
channel name exmple:
1,1a,1b,1c...
2,2a,2b,2c,2d.2e,2f.....
Copy link to clipboard
Copied
Hi Rochan,
Try this code.. š
var dup=[];
if(app.documents.length>0){
var docRef = app.activeDocument;
var mychan = docRef.channels;
var l=mychan.length;
while(l--) {
var mychans=mychan[l].name;
if(searchStringInArray (mychans, dup)==-1){
dup.push(mychan[l].name);
}
else{mychan[l].remove();}
}
}
function searchStringInArray (str, strArray) {
for (var j=0; j<strArray.length; j++) {
if (strArray[j]==str) return j;
}
return -1;
}
Copy link to clipboard
Copied
o = {}, chnnls = [].slice.call(activeDocument.channels); while(chnnls.length)
!o[nme = (shft = chnnls.shift()).name] ? o[nme] = nme : shft.remove()