# 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,

{
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

PS If you’re just starting out I definitely suggest reading through and doing all of the exercises in the Dynamo Primer: http://dynamoprimer.com/en/

2 Likes

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]
{
StartNumber=InitNumber-1;
Collection = Elems;
Range={};
for (i in Collection)
{
StartNumber = StartNumber+1;