If else dynamo

Hi All

How do a create a simple if else statement in dynamo

like =if(length<1500, 1,0)

Im trying to change family type based on a length parameter, but its a bit frustrating because I dont know how the syntax of dynamo works.

Also, in dynamo there are four nodes to the if block, which is test, true, false, and result. How does each node work?

I want to test if a lintel length is greater than x. If its true, change the family to another family type. If not, stay as is

i like using codeblocks, soo If works like this in codeblock:

thanks that makes a lot more sense rather than doing it block by block

so if the length falls between a certain range say between 1000 and 2000 the syntax would be 1000<type1<2000?

This is the formula I wrote for the tags

Lintel 1, 2 and three are the different family types. Length is the length if the lintel, while length 1, 2, 3 are variables( say anything from 1 to 2000).

if(Length < Length 1, Lintel 1, if(and(or(Length 1 < Length, Length = Length 1), Length < Length 2), Lintel 2, if(and(or(Length 2 < Length, Length = Length 2), Length < Length 3), Lintel 3…etc

just need to know how to syntax it properly with the first line of your codeblock

Hi @technitutors ,

You need a && statement, so for example:

Length > 1000 && Length < 2000 ? 1 : 0 ;

You can also use || for or.

okay but its not affecting my lintel. Currently the length is at 900 which should change the family

1 Like

You aren’t giving it a parameter to read. Its looking for length and finding a family type. It can’t read the length parameter on its own.
Try something like this.:


You have to select the element, but it inputs the length this way.

There are two steps you’re missing right now.

First is having the script read data. As shown, you have ‘length’ as an input variable, but it has no relation to the family type you are working with. Look at GJax’s response for an example on how to retrieve the information you want to use (length).

The second is actually writing the revised data. As shown, you’re telling Dynamo ‘output a list containing either this family type or that family type’, but you need to tell Dynamo what to do with this list. Element.SetParameterByName is a companion node to GetParameterValueByName, it does what you logically think it would do. The parameter you want to change, if I remember correctly, is “Type”.

1 Like

Here is somethign that should get what you want. I added the output after @Robert_Younger pointed out your missing output.

Here is the .dyn file if you need it.
Dynamo-ChnageTypeByLength-R19.dyn (12.0 KB)

2 Likes

Maybe this will help:

its giving errors. Length as you can see is 6100. So that is over 100. It should be changing it to type 1 or 2. Almost there I believe but its not changing the lintel to type one or 2. This problem it must select lintels of type 75x75x8ea

connect element to element and type to the value.

What basicly happens is that each element has a list of parameters and you want to change them, depending on the length. That is what Element.SetParameterByName does, it sets the paramater with name Type to your selected type followed by the IF statement.

okay success! I just need it to select multiple elements, not one

Should work the same way, but with the Select Model Elements node.

You will then not change the parameters of 1 element, but of a list of elements! Try it out!

thanks @GJax89 and @Rickkrrd. Now one doesnt manually have to change to the correct schedule! The run of dynamo is like a football match and thats confusing if you dont know what comes before and after.

is there any way to make the length parameters more editable? currently its sitting like this in the code block. Instead of the 1550 rather put say length 1

length<1550?type1:length<=1550 || length<=1650?type2:length<=1650 || length<=1850?type3:length<=1850 || length<=2000?type4:length<=2000 || length<=2000?type5:length<=2000 || length<=2050?type6:length<=2050 || length<=2200?type7:length<=2200 || length<=2450?type8:length<=2450 || length<=2700?type9:length<=2700 || length<=2700?type10:length<=2700 || length<=3250?type11:length<=3250 || length<=3450?type12:length<=3450 || length<=3500?type13:type14;

Quick example, you would replace the string list with your family type list (note that I added a 0 condition at the end of the list for this to work). You could also build a dictionary and reference the dictionary pairings.

thanks a lot. Now theres one more aspect which is copying and flipping lintels. See below

hi give a try on this

is your script for this one?