Conditional output using dynamo

Hello,

As you can see in below snap i have listed values using dynamo.
Now i want to create another list based on the list shown in snap.
for example

  1. if value between 0 to 150 then it should be AA.
  2. 151 to 200 are AB
  3. 201 to 300 are AC.
    I have tried IF node but it is not useful in this case .

if any one can guide me on this it would be very helpful for me…
range in list are from -1130 to 5500.

You could use two if statements in a row, one to figure out if its above or below 150, and if its above then do an if statement for 150-200 or 200-300.

I’d probably just write a small python script with two if statements

1 Like

In the post, I just put an example… I have so many conditions… it might be around 50-60…
I have tried using python script … it is work with one input … but ho two use the same python script for each individual list items

Hello,
here is a possibility to approach things if you have a lot of nested ifs given the length of the study range

Turned into a geometry problem
(the base from 0 to 10)
You still have to make a decision on the border zone between beaches

There is surely a custom node that allows this I think (but I do not know it)

good vision
script:
15 Novembre forum anglais rep2.dyn (30.9 KB)

Cordially
christian.stan

1 Like

Thank you for your response.

I will try the way you have shown in the image.
But I have many elements in my model… based on element location I have made a list of X and Y coordinates.
Now I want to add parameters based on X or Y coordinates.

as posted in 3rd post… have 50-60 conditions. it will have many nested IFs

1 Like

Properly said: I used 10 boxes (from 0 to 1 …9 to 10, 10 lines here and projection of a point on one of them or not)
Your “boxes” of storage will have to be written at one time or another if they are regular, you can automate.

I think you have to make a function (it all depends on your skills, either in designscript or python)

Cordially
christian.stan

1 Like

Hola Amigo @fkp7057 buenas. Is mandatory evaluate positions? the easy way to me is create your list and imposs the values, the other option is transform values to string and use String.Contains to evaluate if match the values ranges, Hope this ideas help you!


Concatenate List and strings.dyn (47.1 KB)

1 Like

You need to create a conditional statement either in python (with list comprehension so it iterates for each item) or in a code block using DesignScript (which will iterate automatically).

The shorthand for a conditional If statement in DesignScript is
condition ? returnTrue : returnFalse;
and reads as “If condition is true then returnTrue else returnFalse.”

You can stack multiple conditions by nesting a new If statement inside a returnTrue or returnFalse value.

1 Like

If you only have the three intervals you described you can use this: (in a Code Block)

Input >= 0 && Input <= 150 ? AA :
Input > 150 && Input <= 200 ? AB :
Input > 200 && Input <= 300 ? AC : "n/a";
4 Likes

I ma


de an example to make it clearer.

function:

def proj(plage:var[],point_test:var[])
{
x=PolyCurve.ByPoints(
Point.ByCoordinates(plage,0,0));

x_cut=PolyCurve.Curves(x);

test_P=Point.ByCoordinates(point_test,-1,0);

P_proj=Point.Project(test_P,x_cut<1>,
Autodesk.Geometry.Vector.ByCoordinates(0,1,0));

return= P_proj;
};

Cordially
christian.stan

3 Likes

Thank you for your simple solution… its worked for me…

the same way i have tried using python but it worked for one value not for list… (ay be something has to do in python).

I would like to thanks all who have put their effort to solve my queries. but @Daan solution was easy for me.

1 Like