Pad leading zero to Room Number

I’m currently renumbering the rooms in my project whereby I’ve used script in a previous post -

The script works great if i’m numbering my rooms from 100 on-words., but i’m having trouble if i start my room numbers at 001. It creates the number as one digit “1” but i would like a 3 digit number “001”

Please see attached a screen grab and script.

RoomRenumber.dyn (19.6 KB)

This may seem basic for some, but i’m still learning the Dynamo World!

Thanks in advance!

This should sort your issue out, the create area was just me creating some lists to use to show you how to add some padding to start of the string.


Thanks for you reply.

I’ve tried to use the padding but it doesn’t change the number of digits as it should (see below)

The PadLeft works for a list but i wish to push that list into the Number to the parameter within the room element.

Do you have any ideas how to push the data across?


Your parameter is likely a Number then. It would have to be a Text parameter in order to be formatted.

1 Like

What’s the error? Or what’s the result? Enabling previews on the node outputs helps.

I don’t & can’t change the Revit Parameter. I was hoping the data I have could be pushed into the Number Parameter within the rooms category.

If your issue is parameter types then that just isn’t possible. If you have a Yes/No parameter you can’t force the value to be a number. If you have a number parameter you can’t force the value to be a string.

Revit is going to format values based on Project Units. Text parameters can be formatted however you want (within the limits of Revit.) You would have to use a Text parameter in this case.

Number is a built in parameter for rooms, which takes a string.

@StuartLarge please expand the previews of the string.padleft node and show what’s happening to the Revit elements using an Element.GetParameterValueByName node with an expanded preview after the set parameter node.

Then completely ignore everything I’ve said. :sweat_smile:
I haven’t had any caffeine yet today.

Nothing happens to the number and no warning. It just remains as one digit.

Here is an example if i choose the number to start from 100 (three digit number)

Maybe that’s the answer if i can’t find a solution to push the current data into the number.
I just thought there could be a way of “converting” the data to be used.

I don’t really want to add an extra project parameter but may have too.

Thanks for your help.

If you expand the previews the issue will be very apparent. You need to look at your data as you go along.

Specifically look here:

The output of the a+b node is longer than 3 characters… therefore you’re not padding anything.

I should have looked closer.

You’re padding your string after you’ve already added the prefix. It’s longer than 3 characters at this point. You need to pad first and then add the prefix.

As i mentioned earlier i’m new to dynamo :upside_down_face:

I would like my room tag to read the following “A-00-001” but currently its reads A-00-1.
If i start the number in the code block at 100 e.g 100…199.1; it works and reads “A-00-100”

The two “00” before -001 are automatically removed for some reason. The script works okay from numbers above 100 but numbers under 100 it automatically removes the two zeros.

100-199 already has 3 digits so there’s no padding needed. You’re creating 000-099 as a number, which is being formatted as a number (look at the node preview). The String.Pad node would work except that you’ve already added the A-00- prefix so the string is now longer than 3 characters so there’s no padding being done.

Previews will help a lot here.

1 Like


Thanks @Nick_Boyts issue resolved! :+1: