Grasshopper

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

Views: 719

Replies to This Discussion

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..

Attachments:

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

Attachments:

RSS

About

Translate

Search

Photos

  • Add Photos
  • View All

Videos

  • Add Videos
  • View All

© 2024   Created by Scott Davidson.   Powered by

Badges  |  Report an Issue  |  Terms of Service