algorithmic modeling for Rhino
Hello,
Considering that all my inputs are only boolean and the output is depending on them (if all of them are True or not), I would like to know if there is a quick way in ghPython to script something like :
if "all the inputs" == True:
....a = True
else:
....a = False
instead of:
if x == True and y == True and z == True and u == True (etc...):
....a = True
else:
....a = False
a would be the output.
The idea would be that by simply adding inputs I woudn't need to change the script.
Best
Tags:
Maybe you can try to multiply them:
a = False
if x*y*z*u ==1: a = True
I've attached an example which demonstrates how one might iterate all the GHPython component input parameters and access their data. Hope that helps..
Hi Roger,
there is not one specific "command" (operator) for that as far as I am aware. But, given that inputs will all be booleans, and if you do not use very strange input names, this single statement will work (and follow Grasshopper tree conventions):
a = reduce(lambda x,y: x and y, (globals()[input.Name] for input in ghenv.Component.Params.Input))
If you allow two statements, then you could import operators, and use operators.and_. Also a = sum(globals()[input.Name] for input in ghenv.Component.Params.Input) != 0
...will do, but is a bit more hackish.
Do any of these fit your needs?
Giulio
--
Giulio Piacentino
for Robert McNeel & Associates
giulio@mcneel.com
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