algorithmic modeling for Rhino
If y is just a list of predeterminated values :
you could create a non multiline panel filled with your value...
X is now the index of your list,
y is the item,
Use a list item to find y according to x.
Key Value search using Sylvains logic should work.
If you really want to create an If statement using code, then it would look like this:
If(x=1, 332, If(x=2, 32, If(x=3, 4423)))
Which is pretty horrific.
--
David Rutten
david@mcneel.com
Tirol, Austria
Thanks David,
Can this be created using grasshopper components?
Sure. Both methods in the attached file.
--
David Rutten
david@mcneel.com
Tirol, Austria
Awesome !!! Is there an index of all the command you can use in formulas ?
f:N->R button in the upper right of the expression editor.
--
David Rutten
david@mcneel.com
Tirol, Austria
Ok, so in that case, you use the B as an else ?
The Grasshopper expression language doesn't support multiple lines of proper conditional statements. This is something I'd like to improve for GH2, probably build the entire language on VB.NET with some special features to maintain backwards compatibility.
Basically an If statement is an If function. It requires three parts, a condition, a result for TRUE and a result for FALSE. So this VB statement:
If (x) then
A
Else
B
End If
Would be written as:
If (x, A, B)
In the GH expression language.
--
David Rutten
david@mcneel.com
Tirol, Austria
Hi dear David
would you please indicate me a good source where to study the correct syntax for GH expression language ?
thanks in advance
regards
Ivan - Veneto IT
No such thing exists I'm afraid. But it's basically a VBScript syntax with a bunch of additional methods (click on the f(x)->R button in the top right of the Expression editor to see them all).
Since conditionals in VBScript typically require more than one line, there's an additional function called If() which takes three arguments, the first one must evaluate to a boolean, the second argument will be returned if the first argument is true and the third argument will be returned if the first argument is false.
The post you're responding to is very old btw. Expressions in GH2 are already operational and they can be full VB.NET or C# methods, and support for python will at some point be added as well.
Many thanks for the helpful answer David.
The f(x)->R gave me a clear view of the available commands, clear also the reason for the if() function syntax
David , congratulation once again for the incredible instrument you have created . GH is fantastic !!!
kindest regards
Ivan - Veneto IT
Welcome to
Grasshopper
Added by Parametric House 0 Comments 0 Likes
Added by Parametric House 0 Comments 0 Likes
Added by Parametric House 0 Comments 0 Likes
Added by Parametric House 0 Comments 0 Likes
Added by Parametric House 0 Comments 0 Likes
© 2024 Created by Scott Davidson. Powered by