It is because the parameters passed to SelectEx do not end up in the correct variables, you can see that in my screenshot above. I'm not sure if there is an error in the parameter template or something, this needs some tinkering to figure out where the problem is exactly. Until fixed, what you tried won't work.
Hello, I add a feature.
"var template = "
I add a template arg "NTHSTART/O", for SelectEx_NTH from the range index of the first selected item.
function SelectEx_NTH(cmd, sourcetab, args){
...
...
var i = 1;
if(args["NTHSTART"].exists) {
if(args["NTHSTART"].value)
i = parseInt(args["NTHSTART"].value,10) //Starting index number
else {
if(sourcetab.selected.count > 0){ //If no index number is specified, start at the first selected file.
for (var eSel = new Enumerator(sourcetab.all); !eSel.atEnd(); eSel.moveNext()){
if(eSel.item().selected)
break;
i++;
}
}
}
}
cmd.ClearFiles();
for(;i<=sourcetab.all.count;i=i+nth)
range += i+",";
Aha, I see! Thank you, I added the NTHSTART option, makes sense! o)
I struggle with your logic about the already selected items though. What's the idea or use case behind? If the NTHSTART option is present (even if it has no value), why take selected items into account? You also seem to use the "sum" of selected items as start number, which makes no sense to me either. Please explain or I have to omit this part. o)
Some improvements..
var nth = parseInt(args["NTH"].value,10), range = "";
Log("NTH : " + nth,"D");
if (!nth){
Log("No 'nth' given.","X");
Log("-","T",-1);
return COMMAND_FAILURE;
}
var i = 1, nthStart = "";
if(args["NTHSTART"].exists) {
if(args["NTHSTART"].value)
nthStart = parseInt(args["NTHSTART"].value,10); // Starting index number
else nthStart = 0;
}
cmd.ClearFiles();
if(nthStart === ""){ // not exist NTHSTART, start from 1
i = 1;
} else if(nthStart>0)
i = nthStart;
else if(nthStart==0) {
if(sourcetab.selected.count > 0){ //If no index number is specified, start at the first selected file.
for (var eSel = new Enumerator(sourcetab.all); !eSel.atEnd(); eSel.moveNext()){
if(eSel.item().selected)
break;
i++;
}
} else i = 1;
} else { // If negative, count backwards from the last, -1 is the last file, and so on
i = sourcetab.all.count + 1 + nthStart;
}
//DOpus.Output("Start at: " + (nthStart==0?nthStart+"-Current selected":nthStart) + " Nth=" + nth + " i=" + i);
if(nth>0){ // Forward increasing sequence
for( ; i<=sourcetab.all.count; i=i+nth)
range += i+",";
} else if(nth<0){ // Reverse decreasing sequence
for( ; i>0; i=i+nth)
range += i+",";
}
for test :
SelectEx EXACT MAKEVISIBLE NTH=3 // start from 1
SelectEx EXACT MAKEVISIBLE NTHSTART NTH=2 //go down from the first selected file
SelectEx EXACT MAKEVISIBLE NTHSTART NTH=-4 //go up from the first selected file
SelectEx EXACT MAKEVISIBLE NTHSTART=2 NTH=2
SelectEx EXACT MAKEVISIBLE NTHSTART=-3 NTH=-3
SelectEx EXACT MAKEVISIBLE NTHSTART=22 NTH=-2