Room Renumber Help

Hey everyone,

I am creating a Dynamo script that renumbers rooms. I am wanting the script to have an initial start value (100) and then a step value (1). I am wanting the script to add 1 to every element in my list of selected rooms starting from my start value. Example, 100, 101, 102, etc… Right now, my custom script will apply my start value to the room number, but will not continue adding one to each element on the list. I am new to programming so if anyone could please help me figure out the logic to this problem I would greatly appreciate it! I have attached my rooms that were renumbered with the script and the Dynamo script itself. The script in my custom node is,

def addOne(initialNumber, numberStep)
start = initialNumber - numberStep;
sum = start + numberStep;
return = sum;

The reason that I subtract the numberStep from the initialNumber is because I want the room numbering to start at the first number given. Without this the first room would be labeled as 101 instead of 100. Thanks in advance for the help!

No need for defining a function here! A code block like below will work:

Here is the node version of the above:

Keep in mind that your rooms are currently ordered by Element ID, so unless they were created in the order you would number them, you’ll probably want to reorder your list of rooms by location. There are posts on the forum you can find for automating room numbering :slight_smile:

PS If you’re just starting out I definitely suggest reading through and doing all of the exercises in the Dynamo Primer:


You’re making more work than you should by trying to an iterative loop as a custom function instead of sticking to basics.

You’re also making it harder on yourself by requiring manual selection, with a node which doesn’t grab things in a logical order but in the order of element ids.

If you REALLY had a good reason to recreate the wheel, you’d need to use an imperative function. Check section 12 of the language guide, but I can’t think of any reason this would be needed.

The imperative chunk of code would look something like this:

NumberRange = [Imperative]
	Collection = Elems;
	for (i in Collection)
		StartNumber = StartNumber+1;
		Range = Flatten(List.AddItemToEnd(StartNumber,Range));

I’ll leave it to you how to best create a function from that.

Thank you so much @awilliams and @JacobSmall!! I know I am doing a lot to make this harder on myself but in the end I feel like I learn a bit more by doing things the “wrong way” first. I ended up combining both of your results into a solution that works well for me. I will definitely go through the Dynamo Primer, it seems to be an incredible resource. Thanks again, Dynamo is a blast to learn.