Convert Certain String Values to specific Number values

I found a way to output specific number values based on certain string inputs using a series of pass-thru if statements. I’m wondering if there is a better/cleaner way? I could create a custom node to clean it up but it seems kind of crazy in the first place …and is quite specific.
strUsageValues beamEquals3Study.dyn (17.8 KB)

Hi @dillon_manning

Here is one of the better way with just few lines of python :slight_smile: :


Great thanks, this is the idea I was looking for but couldn’t find it in a search and haven’t dove into python language yet…just copy and pasting.

I have seemed to get it to work for a list of values; however, I will be feeding a single value through.

@dillon_manning Add List.Create node before python script that would work for you.


Building a dictionary with Dynamo would also allow for use of list levels and lacing.

1 Like

So we must not be on the same page haha. I’m not trying to feed a list through, I am trying to feed a single value which produces a single result (If the input is ‘Girder’, the output is ‘3’ and so on).

This works but I would really like to use python if it means avoiding a packaged node, thanks for the tip!

@dillon_manning You can just change the last line as shown below:


Dictionaries are built in with Dynamo 2.0 and up.

1 Like

Here is dictionary in below 2.0 versions :sunglasses:


I’m still working in 1.3, our team is waiting for 2.1 to be officially released as a stable build. I wish I could mark both of these as solutions!

I’m going to stick with the python coding but I appreciate the help! Now I just have to fix all the other issues… :laughing:

1 Like

FWIW, converting data types to dictionaries in 2.0.2 has made a few of my older workflows exponentially faster. Starting the upgrade process now is likely a good idea as many ‘old school’ packages aren’t compliant with 2.0, stuff will have to be swapped, and your work will have to be reviewed after the update launches.

Like the scouts say: Be Prepared.

Thanks for the input, this is something that has been on my mind. We originally upgraded to 2.0 right away but then found a lot of the packages hadn’t caught up and I heard from a couple sources that 2.0 was unstable. For those reasons we decided to stay with 1.3.

Is 2.0 still considered unstable?