honeybee_ph_utils.input_tools module

Utility functions for cleaning and handling user-inputs

honeybee_ph_utils.input_tools.clean_get(_list: List[T], _i: int, _default: T | None = None) T | None[source]

Get list item cleanly based on index pos. If IndexError, will try getting _list[0] instead.

This is useful for gh-components with multiple list inputs which are sometimes the same length, and sometimes not the same length.

Arguments:

  • _list: Any iterable to get the item from.

  • _i: The index position to try and get

  • _default: The optional default value to use if _list[0] fails.

Returns:

  • Any

honeybee_ph_utils.input_tools.clean_tree_get(_tree, _i, _default=None)[source]
honeybee_ph_utils.input_tools.cleaner_get(_list: List[T], _i: int, _default: T) T[source]

Get list item cleanly based on index pos. If IndexError, will try getting _list[0] instead.

This function requires a default values to be supplied, and therefor will never return None (unless the default value is None). This is more type-safe than the ‘clean_get’ function.

This is useful for gh-components with multiple list inputs which are sometimes the same length, and sometimes not the same length.

Arguments:

  • _list: Any iterable to get the item from.

  • _i: The index position to try and get

  • _default: A required default value to use if _list[0] fails.

Returns:

  • Any

honeybee_ph_utils.input_tools.input_to_int(_input_value: Any, _default: Any | None = None) int | None[source]

For ‘selection’ type inputs, clean and convert input to int.

ie: if the Grasshopper input allows:

“1-A First Type” “2-A Second Type”

will strip the string part and return just the integer value, or raise SelectionInputError.

honeybee_ph_utils.input_tools.memoize(func)[source]

Simple caching decorator using function arguments as key.

Uses the Grasshopper ‘sticky’ dict to store values.

https://book.pythontips.com/en/latest/function_caching.html

Usage: >>> @memoize >>> def fibonacci(n): >>> if n < 2: return n >>> return fibonacci(n - 1) + fibonacci(n - 2) >>> >>> fibonacci(25)