Increment list index by x

Hi all,

I am trying to update the revision sheets on one of my projects using Dynamo.

I don’t seem to be able to get the indexes on my list to update as I wont them, basically taking the sheet’s latest revision number and add “1”, i.e 001 + 1 = 002. I know this is mathematically incorrect but this is what I’m trying to achieve (as per the code blocks showing)

4 Likes

Vikram is correct how to add padding.

The “+” node issue is happening because it will add the number to the end of the string input and not add them together.
This happens because the output from the parameter is a string and not a number, this will mean you would have to add the “String.ToNumber” node prior to inputting it to the “+” node to add the two numbers together.

1 Like

2 Likes

For your code to work with numbers greater than 10 and less than 100, it will have to be extended a little
x<10?"00"+(x+1):"0"+(x+1);

1 Like

Also, one line IF statements can be nested, should you need to go to 4 characters or greater:

x < 10 ? “000” + x+1 : x < 100 ? “00” + x+1 : “0” + x+1;

1 Like

Hi guys,

Thank you for you helpful responses. This is how got my definition to work, mostly using Vikram suggestion.

I found that for normal lists all the suggestions seem to work however, when using data from a var you need to add a few extra nodes, as per the image here.

Again, many thanks all

1 Like

Thanks for this! :slight_smile:

Thank you Vikram

1 Like

Using Design Script…

String.PadLeft(String.ToNumber(n)+1+"",3,"0");

1 Like