Page 1 of 1

increment bracketed ranges

Posted: Tue Oct 27, 2009 2:15 pm
by Sashaz
Hi, I'm trying to dl a sequence whose urls finish

..../images/ma3900_002v-003r.jpg
..../images/ma3900_003v-004r.jpg

and so on.

In build gallery, I've got as far as a content sequence

....images/ma3900_[001-125;1]v-[$001]r.jpg

But here the range reference merely repeats the first number. So my question is can I increment the range reference by a definable number above or minus the first? Namely, in this case, the number on the left +1.
I tried typing in +1, but it didn't work!!!

Many thanks, Sasha

Re: increment bracketed ranges

Posted: Tue Oct 27, 2009 2:41 pm
by Giorgio Maone
You need to define a custom JavaScript function for that.
First, enter the following range definition:

Code: Select all

..../images/ma3900_[001-125]v-[add([$1], 1)]r.jpg
When you switch on the "JavaScript Functions" tab, you'll fine a new "add" function has been added.
Edit its body as follow way:

Code: Select all

return arguments[0] + (arguments[1]);
Hope it helps.

Re: increment bracketed ranges

Posted: Tue Oct 27, 2009 4:09 pm
by Sashaz
Dear Giorgio. many thanks for your speedy reply!
Unless I got something wrong, this works great past 100 in the sequence, but it isn't generating the necessary padding for numbers 2-99, which have to be three digits, i.e. 002r, or 099r respectively (At the moment I'm getting 2r and 99r) Is there a way of incorporating the [$001] padding? I tried to change it to that and it didn't work.
Also, out of interest, are there a subtract/divide/multipy commands that function in the same way as add?
Many thanks, Sasha

Re: increment bracketed ranges

Posted: Tue Oct 27, 2009 5:19 pm
by Giorgio Maone

Code: Select all

var base = new String(arguments[0]);
var padding = base.replace(/\d/g, '0');
var operand1 = parseInt(base.replace(/^0*/, ''));
var operand2 = arguments[1];

// change "+" with "*", "/" or "-" for other operations
var result =  padding.concat(operand1 + operand2); 

return result.substring(result.length - padding.length);

Re: increment bracketed ranges

Posted: Tue Oct 27, 2009 5:58 pm
by sashaz
Hi Giorgio, many thanks for that. It's still not working, not sure if I'm doing it right. I pasted it into the add javascript function. which now looks like this:

return arguments[0] + (arguments[1]);
var base = new String(arguments[0]);
var padding = base.replace(/\d/g, '0');
var operand1 = parseInt(base.replace(/^0*/, ''));
var operand2 = arguments[1];
var result = padding.concat(operand1 + operand2);
return result.substring(result.length - padding.length);

was I supposed to put in values for any of these elements?
As before, I'm using the range definition
/images/ma3900_[001-125]v-[add([$1], 1)]r.jpg

Many thanks, Sasha

Re: increment bracketed ranges

Posted: Tue Oct 27, 2009 6:04 pm
by Giorgio Maone
Please copy & paste it verbatim (i.e. remove the original "return" statement which you kept in place).

Re: increment bracketed ranges

Posted: Tue Oct 27, 2009 6:59 pm
by Sashaz
Hi, ok, thanks for that. I pasted it as directed. But I still get the same result as the first add function! Is there anything else that I might have set wrong?
Many thanks, Sasha

Re: increment bracketed ranges

Posted: Tue Oct 27, 2009 7:14 pm
by Giorgio Maone
Please double check there's only one return statement.

Re: increment bracketed ranges

Posted: Tue Oct 27, 2009 7:26 pm
by Sashaz
I copy pasted it, so its exactly as you gave it:
Thanks, Sasha

var base = new String(arguments[0]);
var padding = base.replace(/\d/g, '0');
var operand1 = parseInt(base.replace(/^0*/, ''));
var operand2 = arguments[1];

// change "+" with "*", "/" or "-" for other operations
var result = padding.concat(operand1 + operand2);

return result.substring(result.length - padding.length);

Re: increment bracketed ranges

Posted: Tue Oct 27, 2009 7:34 pm
by Giorgio Maone
OK, keep the code as it is now but change the range definition into

Code: Select all

....images/ma3900_[001-125;1]v-[add("[$001]", 1)]r.jpg
(notice the extra zeroes and double quotes).

Re: increment bracketed ranges

Posted: Tue Oct 27, 2009 7:52 pm
by Sashaz
Excellent! Works perfectly! It's a really neat solution. Thanks very much! Sasha