What if you have more than 1 if statement?

Hey everyone, ive been looking through the forum for examples on multiple if statements. But, all i could find are one if statement examples. Does anyone know how to do this with nodes or design script?

1 Like

Try this code block:

a==6?
	"Family 1 Goes Here":
	a==2?
		"Family 2 Goes Here":
		"Family 3 Goes Here";

You can go as deep as you like, and remove the quotes to use different families which will become inputs to the node instead of strings.

7 Likes

Hey Jacob,

Do i just put in the family name where it says “Family 1 Goes Here”? When i remove the quotations i get an error.

Post what you did so I can walk you through it. All versions of Dynamo for Revit was uninstalled by IT in my computer last night so unfortunately I can’t do it directly for you.

HOLY MOLY! if this is what you meant, it worked!!! thank you thank you jacob

2 Likes

That was it. For speed sake remove the a; b; c; … g; part. The input variable can be called after the fact in this case and it will make things read better and can help with performance on larger graphs too.

2 Likes

thank you once again!

Hi Jacob.

I have a scenario where a STRING response is required to be returned, depending on whether a value occurs between ranges of values. But l have tried it with IF statements, <=, >= etc, but no joy.

Any thoughts on what l am doing wrong?

image

1 Like

My value is 8.085, therefore l am expecting response ‘b’, but l get “”

Are you certain all your values are “flattened”?

You don’t have a valid conditional statement. You need to use && for a range of values.
image

5 Likes

Just ask them in sequence - if it’s less than 5.4 then return the first value. If the value wasn’t less than 5.4 but it’s less than 8.5 then your number falls between 5.4 and 8.5. No need to check if it’s > 5.4 a second time.

That said, the logical statement you couldn’t find is:

T> 5.4 && T< 8.4

Though the upper value should likely be a <= test.

You’re still doing 2x the amount of computations here - Only ask something once unless you have a requirement to do it twice. By asking smallest to largest you’ll remove parts from the set sequentially.

5 Likes

I am doing something wrong here but I cannot figure it out. Any of you have an Idea?

Edit: List.Firstitem output was a string not a number. Simple String.ToNumber and it works fine now.
Some times you get drawn into what you are doing and you forget to look at what you have done.

What is the Object.Type for “Days”?

By the looks of it, I’d wager it’s not an integer.

1 Like

Ya sorry it was a string. I was zoomed in to much and forgot what the data was.

Hey Jacob,

This worked for me when I just had a single item as the then (i.e. Family 1 Goes Here"). I need a list to be created differently based on the input. When I use the following, it only results in the first item of the list:

Do I have the syntax wrong?

Thanks,
Scott

Here’s a link to the original post: What if you have more than 1 if statement? - Revit - Dynamo (dynamobim.com)

If does not utilize the internal lacing mechanisms, so it can’t process variable depth lists. Instead separate the single output into two or three.
First have your if statement return an index number as a new variable, then build a list of all your desired values, and then pull the resulting set from the list.

Looks like this:

2 Likes

I think @jacob.small nailed it. I started to give it a try before he posted and then continued for my own benefit. Thanks, for the clean solution Jacob.

Failed solution 1:

Failed solution 2 (Basically the same as above):

Working solution (same concept as Jacobs):

It looks like the new if node will be able to accommodate this function.

2 Likes