Set parameters for two or more elements - calculation error

I have a problem with set parameters for two or more elements.
Script analize 3 parameters and based on them choose right formula - calculation 1 or 2 or 3.
After that I have 3 calculated values and then set them to one element.
If I try set parameters to one element, everything is ok (checked for every calculation formula 1 or 2 or 3).
I checked calculation for 5 different elements - one after another - script choose sometimes formula 1, 2 or 3 and always get right score.
But If I choose two or more elements to calculate at one moment, result for first element is ok, but second is wrong. How to fix it?
The idea graph to see below:

Please show what you have tried in Dynamo, from this sketch it is impossible to tell what is wrong.

Agree with Daan. Based on your image you’re doing nothing wrong, assuming you’re handling all your filtering correctly. So you’re either handling something wrong in your graph or you’re representing it wrong in your image.

This script is a little complex and complicated, but I see the step where answer is wrong
,if I calculate two or more elements.
Maybe step by step we’ll fix it.
As You can see below at key 2 is wrong value. Should be 0, not 1.22, because a1 is not equal a2.
Maybe code block on the right is wrong?

hope this help

a1==a2 && x==0.01 &&  y==0.01 ?2.19
:a1==a2 && x==0.01 && y==0.1?110
:a1==a2 && x==0.01 && y==0.2?438
:a1==a2 && x==0.01 && y==0.3?985
:a1==a2 && x==0.01 && y==0.4?1591


It is hard to say without showing what is being input into the Code Block and how it looks complete.
Also, if you have so many possible values, use a Dictionary instead. The method you are using right now is slow, hard to edit and error prone.

I.e. x == 0.01 && y == 0.01 could be translated into 0.01-0.01 as a key for said dictionary.

1 Like

Could You explain, how can I change it to Dictionary?


I would create the Dictionary within a Python Script node, as follows:

The dictionary:

OUT = {

I also added the following Python script to automatically convert the numbers to strings* and to join them together. I had to do this in Python because when you try to convert numbers to strings directly in Dynamo you always get trailing zeroes (or there is a way that I’m not aware of)

*This is needed because a dictionary only accepts strings as keys.

strlist1 = IN[0]
strlist2 = IN[1]

def num_to_str(strlist1):
    return [str(num) for num in strlist1]
def join_lists(list1, list2):
    return [f"{item1}-{item2}" for item1,item2 in zip(list1,list2)]

OUT = join_lists(num_to_str(strlist1),num_to_str(strlist2))

Generally in this long code block I try to implement below table.
And if I read parameters x and y of specific element i can get a number.
f.e. x=0.3 and y=0.3 => 1.78
x=0.5 and y=0.5 => 1.35.
So, if You talk that this method is slow, it is a other option to input that table?
My script has ~ 8 table like this, so if i click Run, I have a score for about 2 minutes :slight_smile:

If I check Dictionaries I give feedback of results.

hello, you can also follow this approach by interpolation (you can always interpolate on the mesh points)


1 Like

Problem for proper read parameters from two or more elements in code block was related to square brackets.
As You can see at screen below.
If I read parameters from “One” element all calculations are good - square brackets in equations are not required.
But If I try read parameters from two or more elements and every parameter was group in list
then in code block all variables MUST BE in square brackets to do proper calculations.

All right, it’s almost done that I want to achieve…
I have 5 elements and set them values for parameters dP_1, dP_2 and dP_3.
I have two routes of calculations:
By first route I must set parameters for elements 2, 4 and 5 - like below

By second route of calc. I must set this 3 parameters for ONLY elements 1 and 3.

How can I achieve it?

Hola amigos buenas, i’m back from vacations :slightly_smiling_face:
Amigo @AeM_86 I leave you an alternative solution to dictionaries, directly evaluate values and work with table indices just be careful that your lists are in the right order, I hope it helps you!

Search in Tables.dyn (18.5 KB)

Hello @gilberto.arechigaiba Thanks, cool tip :wink: Script search values much faster than in code blocks

1 Like

Why in first item of “list.index” is -1 instead of 5?
Second and third are ok.

Elements from list 1 are objects: system double
Elements from list 2 are objects: system double
list are objects: system double
If value is >1 then return -1. But why? I have no idea…

Edit: Solved
“String from Object” as input “List.IndexOf”