Same code Python with a different result in dynamo and pythontutor

Hi Guys,

I wrote a code in phyton and work perfectly in one platform call pythontutor(to learn python), but when I put the code in dynamo, he not work so well and show me other results,
Does someone know the problem??

pythontutor:


Dynamo:
Capturar2

The script:

from math import sqrt
    Q = [[0.25,0.25,0.25,0.25,0.16,0.16],[0.25,0.25,0.25,0.25,0.19,0.16]]
    D = [[21.6,21.6,21.6,17,17,1],[21.6,21.6,21.6,17,17,17]]
    B = [17,21.6,27.8,35.2,44,53.4,66.6,97.8] #List Base.
    def recalculate(a,b):
        V = 4000*a/(b*b*3.1415)
        Vaz = 14*sqrt((b/1000))
        if V < 3 and  V< Vaz:
            return False
        else:
            return True
    for i, list in enumerate(Q):
        for j, number in enumerate(list):
            a=recalculate(number, D[i][j])
            if a==False: 
                print("OK")
            else:
                print("Recalculate")
                aux=0
                while True:
                    b=recalculate(number, B[aux])
                    if b==False:
                        break
                    else:
                        aux+=1
                D[i][j]=B[aux]
    OUT = D

There are no print statements in Python scripts inside Dynamo. You will have to use the append method to add what is inside the print statement to a list and output it.

1 Like

I’m really don’t know what to do… =(
I do my best in that script and he don’t work…T.T

Don’t despair, will gladly walk you through it. But can you upload the code preformatted please?

for el in listOne:
    print("I like preformatted text")

It will save me some time. Thanks!

2 Likes

Test.dyn (6.5 KB)

# Ativar suporte de Python e carregar biblioteca DesignScript
import clr
clr.AddReference('ProtoGeometry')
from Autodesk.DesignScript.Geometry import *
from math import sqrt

Q = IN[0]
D = IN[1]
B = [17,21.6,27.8,35.2,44,53.4,66.6,97.8] #List Base.

def recalculate(a,b):
    V = 4000*a/(b*b*3.1415)
    Vaz = 14*sqrt((b/1000))
    Console(context=locals())
    if V < 3 and  V< Vaz:
        return False
    else:
        return True
        
for i, list in enumerate(Q):
    for j, number in enumerate(list):
        a=recalculate(number, D[i][j])
        if a==False: 
			break
        else:
            aux=0
            while True:
                b=recalculate(number, B[aux])
                if b==False:
                    break
                else:
                    aux += 1
            D[i][j]=B[aux]
            
# Atribua a sua saída para a variável OUT.
OUT = D[i][j]

Hi @joaoluiz.sribeiro,

took a look into your code, but can you elaborate a bit what’s your end goal? I mean, the kind of operation that is going or how is the process to get to the result dat you want?

Thanks!

We have two list Q and D.
In the script after you make these two formulas (V = 4000Q/DD3.1415)) and (Vaz = 14sqrt((D/1000))),we will obtain 2 new lists (V and Vaz).We will need to meet these two conditions: V < 3 and V < Vaz.
If these conditions were accepted, the final result is the list D. But if you don’t satisfy one condition, you will need to replace the item how not pass in list D to one item in List B, you will try each number until satisfies these two conditions(V< 3 and V<Vaz),so the final result, in that case, is a new list D with the element who was replaced by the number in list B.
Do you understand? =)

Hi @ joaoluiz.sribeiro,

It explains me better the purpose of this code there. From the formulas used, it seems that you are trying to calculate something about the flow regime in closed conduits, but it is not very clear. Explain better what should be done by the code.

Translated by admin. Original text below.


Oi @joaoluiz.sribeiro,

Me explica melhor o objetivo desse código ai. Pelas formulas usadas, parece que você tá tentando calcular algo sobre regime de escoamento em condutos fechados, mas não tá bem claro. Explique melhor o que deve ser feito pelo código.

@lucas_20, the official forum language is English. This is a requirement for search to work. Please keep all posts to English in the future, or post both the translation and your original text similar to above.

sorry, I just tried to understand better the problem because he seems to have some difficuties to express in english

1 Like

Sorry joao, was trying to understand your explanation. I think you explanaided quite well, the problem is that, I think, there are too many variables and its taking data from many lists. Can you elaborate something graphic? Or just point me how you obtain the two first values with formulas.
Thanks!

Guysss!!! =D
After 2 days debugging that shit, I have finally found the problem!!! =D
I have changed a lot the script to work.
the principal problem is when an applied division in python inside the Revit, he doesn’t interpret the number after the dot. (confusing)
Example:
17/100 = 0
17/100.00 = 0.17
The second problem is one in the input (KKK =D), but I found easily.

Thanks for help =)!
@architectcoding
@lucas_20
@jacob.small

P.S: Yeah man! I create a script that calculates and design in Revit the water pipes. (NBR 5626)
The script creates a schedule with information of design, he changes the colors and overrides the size of pipes with problems.
Pic:

3 Likes

Congratulations Joao! Amazing job you have done!
Well, here is the explanation for your first problem:

Congrats again!

1 Like

Congratulations, How this routine works? you sell

Sorry,no…