If - else statement , while loop , Imperative block

Okay…simple then: don’t use Dynamo Studio! :joy:
I’ll just use Dynamo within Revit then or Dynamo Sandbox. :+1:

Never the less…THANKS for all your help!!

1 Like

@Mike_Wellink so the same codeblock fails to finish executing in dynamo studio but runs fine in the other two applications -? Are they the same version?

My topics is related to this I have list of X and Y. X is consider as true & Y is false. If my output is true then I want same Y value and X+100 value if my output is false then I want Y+100 and X is same vale. By the above information how to create a code block.

I don’t know what is wrong in this code block? It is asking closeparen expected.

How to handle this kind of issues with Dynamo?

You have no indentation.

if statements need two = signs if you want to check if it is equal to, a single equal sign means you are assigning a variable. Try changing it to (sc == 100)

you was right,

I have corrected

sc;
d= [Imperative]
{if (sc==100) {
return = -20;
} else {
return = 0;
}};

How to add ‘elif’ for multiple conditions in code block?

have tou tried elseif ?

http://dynamobim.org/wp-content/links/DesignScriptDocumentation.pdf

1 Like

Is there any way I can add ‘elif’ for multiple condition in code block? If I dont want to go for python script?

It is working. Thank you for reply.

sc;
d= [Imperative]
{if (sc==25) {
return = -37.1;
} elseif (sc==50) {
return = -49;
} elseif (sc==75) {
return = -37.2;
} elseif (sc==100) {
return = -33;
} elseif (sc==150) {
return = -37.4;
} elseif (sc==200) {
return = -37.5;
} else {
return = 0;
}};

2 Likes

Just came across this. What does [Imperative] mean and do? Thanks

Imperative is a design script function. You can read more about it here: http://designscript.io/DesignScript_user_manual_0.1.pdf

Imperative programming is characterized by explicit ‘flow control’ using for loops (for iteration) and if statements (for conditionals) as found
in familiar scripting and programming languages such as Python, C# or Java. Imperative programming is useful to perform iteration, either
stepping through a collection or to perform some iterative feedback or optimisation loop. Imperative programming can also be used for
complex conditional logic. Imperative programming is particularly relevant to users who have experience with existing scripting and
programming languages.

While I am here, a way to do an else if statement inside a codeblock without the use of Imperative statements would be to add a second if statement in the false return. For example:

x > 5? False: (x < 0? False: True);
would be the same as python of:

if x > 5:
    false
elif x < 0:
    false
else:
    true
2 Likes

Thank you for this example, was searching for over an hour and this script works for me after some tweaking for my if statement

1 Like

Hi, I just tried what you suggested but for some reason I’m not getting anything.
My original goal was to check if an element is a list, like the top nodes in attached pic. When that didn’t work I tried your code, like in the bottom nodes and that is also returning null.
Am I doing somethin wrong? Is there something I am missing?

Update: I tried writing your short code on a new file and it works - I guess when I got an error window with my first try it damages the file for further code.
So my question would be: how would to check in the imperative language if the input object is a list?

I have the same question also!

@zvith here is one option using DesignScript and an If Statement :slight_smile:

List.Count(inp) > 1 ? true : false;
1 Like