If test dist1 and dist2

Hi all,

I’m so confused on how to do a simple test. I’m looking to do a
old vb test, I just don’t see how to flip the distance value based on test below.
I tried the < test and get a false for a dist1 = 250 and dist2 = 500, but I don’t see how to
override the current value for dist1 to the value dist2 = 500.

thank you for any hints.
John

If DIST1 < DIST2 Then
DIST1 = DIST2
Else: DIST1 = DIST1
If DIST2 < DIST1 Then
DIST2 = DIST1
Else: DIST2 = DIST2
End If
End If

Is this in python or in DesignScript (codeblock)? The syntax is obviously different depending on what you’re coding in. Also not sure if your code was originally formatted but you need to use the preformatted text option (</> in toolbar above) if you’re posting formatted code. It looks like there’s some missing formatting.

#Python
if DIST1 < DIST2:
    DIST1 = DIST2
if DIST2 < DIST1:
    DIST2 = DIST1

In python, you can rewrite the variable since it’s all persistent. This also means that you don’t need an else statement and you don’t need to rewrite a variable as itself.

#DesignScript
DIST1 < DIST2 ? DIST2 : DIST1;
DIST2 < DIST1 ? DIST1 : DIST2;

DesignScript is typically not persistent so you don’t want to rewrite variables. Instead, you can just return the value that you want: condition ? returnTrue : returnFalse;

In your specific case, it seems like you just want both variables to be set to the maximum of the original two values. You can just use a maximum function instead and use that value. No need to manage two variables.

3 Likes

…or as Nick alluded:

bigD = max(DIST1, DIST2)

,and call it a day.

Nick,

Thanks, it looks like I need to learn a little DesignScript or python. This doesn’t look too bad, even if I’ve never used either. Thank you for the help.
John

maybe it is

The provided text discusses a coding problem where the user wants to compare two distances (DIST1 and DIST2) and update them so that both variables hold the maximum value. The user initially attempts this using VB-like syntax. Nick_Boyts suggests solutions in both Python and DesignScript. In Python, the solution is concise: bigD = max(DIST1, DIST2)
. This leverages Python’s ability to directly rewrite variables, eliminating the need for conditional statements
. The DesignScript solution is similar in concept but uses a ternary operator for conciseness
. The user ultimately expresses gratitude for the help and indicates they intend to learn either Python or DesignScript
.

Related

Pro

If test dist1 and dist2 - Lists-Logic - Dynamo
Current
Ask AI anything…

http://forum.dynamobim.com
http://forum.dynamobim.com

If test dist1 and dist2 - Lists-Logic - Dynamo

. Also not sure if your code was originally formatted but you need to use the preformatted text option ( </> in toolbar above) if you’re posting formatted code. It looks like there’s some missing

I use an AI assistant for coding