Search for Item and Return a value

I am trying to search a Level name output for the word “First” and have it return me a value of “01”. What is the best way to achieve this?

The end goal is to have a script that will process the levels (First Floor, Second floor…etc.) and return values (01, 02…etc). This is a small part of a view naming tool, so that when I create views, I can name them with a numerical value corresponding to their level.


try one of these examples

Get all levels, sort by elevation, feed that list into a code block like so:


@Nico_Stegeman I tired the first two, they did not return the values was hoping for. the input would be “FIRST FLOOR” and I am trying to output that to just “01”. I think I might be able to change them up a bit to get the desired output.

@JacobSmall I tried a few variations of the designscript, but kept getting errors like such;


Like this?

You need to define Floor as a string (using “Floor” ) You’re using ``Floor´´ not “Floor”

1 Like

@viktor_kuzev I love the simplicity of your idea. It definitely achieves my goal, but unfortunately I would have to modify it on a by-project basis. The downside for my application is that the Levels have to be in a particular order or else it incorrectly names them.

@Jonathan.Olesen That was a silly mistake on my part…

Then I’m not sure what’s the final goal.

In this image Option 1 represents a possible way to rename all levels based on their elevation.
Option 2 Looks for a certain keyword and replaces it with a certain value.

My bad @viktor_kuzev, I am trying to read the level names, replace the names with a level number (first floor = 01…) and use those outputs to rename views created from those levels.

Ex: first Floor = 01, and I ma making a mechanical plan through Dynamo.
-The new View Name = “HVAC Plan-01” and Title On Sheet = “FIRST FLOOR HVAC PLAN”

The script is set to read the existing levels in the Arch link, create levels in my model based on the Arch levels, Create views based on disciplines chosen (through Data-Shapes), and rename the created views.

Switching to string based ordinals (first, second, third…) is difficult. You’re likely going to want to create a dictionary for this to provide longer term flexibility (unless there is a package I’m not aware of in which case you can use that).

Since I’m not sure which version of Dynamo you’re in, I’m sidestepping the issue of changing dictionary methods/types, and instead will provide two options for nested if statement for you to work with:

The top option replaces 01 with first, 02 with second, and so on. Note that I stopped at 10 because I didn’t feel like coding up every ordinal number in the world as written text.

The bottom option replaces 01 with 1st, 02 with 2nd, and 99 with 99th. This is obviously more flexible, easier to write up, and less space consuming (twenty second vs 22nd). Also of note: neither option takes into account basement floors. Following the logic in the options provided should get you what you need though.

I Agree with @JacobSmall on the dictionary.
But I find it simpler to use a Python for this: