Grasshopper

algorithmic modeling for Rhino

Totally a noob question.... after a couple years of working with Grasshopper, just starting to get into Python by writing small scripts as Python components in my definitions to get better acquainted with the language.

Trying to write a very simple Python script to take a list of values in a list, and progressively add them until a predetermined limit has been reached, then return the number of values added together to get to the limit.

I assume its some kind of looping function, but not familiar with how to count loops or add from a list incrementally.

Views: 4984

Replies to This Discussion

Do you mean something similar to the mass-addition component, but with a conditional statement telling it to stop adding when a certain numeric value has been reached?

Exactly. With some kind of output to say how many numbers it had to add to get to that point.

There you go :)

Attachments:

That is awesome, thank you very much!

Thanks for the annotations as well, it will help me learn!

No worries. I just updated the file to demonstrate how to write this as a function, as well as the Python concept of "unpacking". Also note how I stick to lower-case variable names for everything except the input/output parameters of the GH component. This is the standard Python naming convention. However I also break convention in the naming of the function. It would be considered more "Pythonic" to use underscores like so "massaddition_with_limit". I just prefer to both read and write camel-case like so "massadditionWithLimit". Hope that helps..

Attachments:

RSS

About

Translate

Search

Videos

  • Add Videos
  • View All

© 2024   Created by Scott Davidson.   Powered by

Badges  |  Report an Issue  |  Terms of Service