increment bracketed ranges
increment bracketed ranges
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
..../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
Mozilla/5.0 (Macintosh; U; PPC Mac OS X 10.5; en-US; rv:1.9) Gecko/2008061004 Firefox/3.0
- Giorgio Maone
- Site Admin
- Posts: 9524
- Joined: Wed Mar 18, 2009 11:22 pm
- Location: Palermo - Italy
- Contact:
Re: increment bracketed ranges
You need to define a custom JavaScript function for that.
First, enter the following range definition:
When you switch on the "JavaScript Functions" tab, you'll fine a new "add" function has been added.
Edit its body as follow way:
Hope it helps.
First, enter the following range definition:
Code: Select all
..../images/ma3900_[001-125]v-[add([$1], 1)]r.jpg
Edit its body as follow way:
Code: Select all
return arguments[0] + (arguments[1]);
Mozilla/5.0 (Windows; U; Windows NT 5.2; en-US; rv:1.9.1.3) Gecko/20090824 Firefox/3.5.3 (.NET CLR 3.5.30729)
Re: increment bracketed ranges
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
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
Mozilla/5.0 (Macintosh; U; PPC Mac OS X 10.5; en-US; rv:1.9) Gecko/2008061004 Firefox/3.0
- Giorgio Maone
- Site Admin
- Posts: 9524
- Joined: Wed Mar 18, 2009 11:22 pm
- Location: Palermo - Italy
- Contact:
Re: increment bracketed ranges
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);
Mozilla/5.0 (Windows; U; Windows NT 5.2; en-US; rv:1.9.1.3) Gecko/20090824 Firefox/3.5.3 (.NET CLR 3.5.30729)
Re: increment bracketed ranges
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
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
Mozilla/5.0 (Macintosh; U; PPC Mac OS X 10.5; en-US; rv:1.9) Gecko/2008061004 Firefox/3.0
- Giorgio Maone
- Site Admin
- Posts: 9524
- Joined: Wed Mar 18, 2009 11:22 pm
- Location: Palermo - Italy
- Contact:
Re: increment bracketed ranges
Please copy & paste it verbatim (i.e. remove the original "return" statement which you kept in place).
Mozilla/5.0 (Windows; U; Windows NT 5.2; en-US; rv:1.9.1.3) Gecko/20090824 Firefox/3.5.3 (.NET CLR 3.5.30729)
Re: increment bracketed ranges
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
Many thanks, Sasha
Mozilla/5.0 (Macintosh; U; PPC Mac OS X 10.5; en-US; rv:1.9) Gecko/2008061004 Firefox/3.0
- Giorgio Maone
- Site Admin
- Posts: 9524
- Joined: Wed Mar 18, 2009 11:22 pm
- Location: Palermo - Italy
- Contact:
Re: increment bracketed ranges
Please double check there's only one return statement.
Mozilla/5.0 (Windows; U; Windows NT 5.2; en-US; rv:1.9.1.3) Gecko/20090824 Firefox/3.5.3 (.NET CLR 3.5.30729)
Re: increment bracketed ranges
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);
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);
Mozilla/5.0 (Macintosh; U; PPC Mac OS X 10.5; en-US; rv:1.9) Gecko/2008061004 Firefox/3.0
- Giorgio Maone
- Site Admin
- Posts: 9524
- Joined: Wed Mar 18, 2009 11:22 pm
- Location: Palermo - Italy
- Contact:
Re: increment bracketed ranges
OK, keep the code as it is now but change the range definition into
(notice the extra zeroes and double quotes).
Code: Select all
....images/ma3900_[001-125;1]v-[add("[$001]", 1)]r.jpg
Mozilla/5.0 (Windows; U; Windows NT 5.2; en-US; rv:1.9.1.3) Gecko/20090824 Firefox/3.5.3 (.NET CLR 3.5.30729)
Re: increment bracketed ranges
Excellent! Works perfectly! It's a really neat solution. Thanks very much! Sasha
Mozilla/5.0 (Macintosh; U; PPC Mac OS X 10.5; en-US; rv:1.9) Gecko/2008061004 Firefox/3.0