ladybug_rhino.grasshopper module

Functions for dealing with inputs and outputs from Grasshopper components.

ladybug_rhino.grasshopper.all_required_inputs(component)[source]

Check that all required inputs on a component are present.

Note that this method needs required inputs to be written in the correct format on the component in order to work (required inputs have a single _ at the start and no _ at the end).

Parameters

component – The grasshopper component object, which can be accessed through the ghenv.Component call within Grasshopper API.

Returns

True if all required inputs are present. False if they are not.

ladybug_rhino.grasshopper.bring_to_front(component)[source]

Bring a component to the front of the canvas so that it is always executed last.

Parameters

component – The grasshopper component object, which can be accessed through the ghenv.Component call within Grasshopper API.

ladybug_rhino.grasshopper.component_guid(component)[source]

Get the unique ID associated with a specific component.

This ID remains the same every time that the component is run.

Parameters

component – The grasshopper component object, which can be accessed through the ghenv.Component call within Grasshopper API.

Returns

Text string for the component’s unique ID.

ladybug_rhino.grasshopper.data_tree_to_list(input)[source]

Convert a grasshopper DataTree to nested lists of lists.

Parameters

input – A Grasshopper DataTree.

Returns

listData – A list of namedtuples (path, dataList)

ladybug_rhino.grasshopper.de_objectify_output(objectified_data)[source]

Extract the data from an object that was output from the objectify_output method.

Parameters

objectified_data – An object that has been output from the objectify_output method for which data will be returned.

ladybug_rhino.grasshopper.document_counter(counter_name)[source]

Get an integer for a counter name that advances each time this function is called.

Parameters

counter_name – The name of the counter that will be advanced.

ladybug_rhino.grasshopper.flatten_data_tree(input)[source]

Flatten and clean a grasshopper DataTree into a single list and a pattern.

Parameters

input – A Grasshopper DataTree.

Returns

A tuple with two elements

  • all_data – All data in DataTree as a flattened list.

  • pattern – A dictionary of patterns as namedtuple(path, index of last item on this path, path Count). Pattern is useful to un-flatten the list back to a DataTree.

ladybug_rhino.grasshopper.get_sticky_variable(variable_name)[source]

Get a variable from sticky memory. Will be None if the variable is not set.

Parameters

variable_name – The name of the variable to get.

ladybug_rhino.grasshopper.give_popup_message(message, window_title='', icon_type='information')[source]

Give a Windows popup message with an OK button.

Useful in cases where you really need the user to pay attention to the message.

Parameters
  • message – Text string for the popup message.

  • window_title – Text string for the title of the popup window. (Default: “”).

  • icon_type

    Text for the type of icon to be used. (Default: “information”). Choose from the following options.

    • information

    • warning

    • error

ladybug_rhino.grasshopper.give_remark(component, message)[source]

Give an remark message (giving a little grey ballon in the upper left).

Parameters
  • component – The grasshopper component object, which can be accessed through the ghenv.Component call within Grasshopper API.

  • message – Text string for the warning message.

ladybug_rhino.grasshopper.give_warning(component, message)[source]

Give a warning message (turning the component orange).

Parameters
  • component – The grasshopper component object, which can be accessed through the ghenv.Component call within Grasshopper API.

  • message – Text string for the warning message.

ladybug_rhino.grasshopper.hide_output(component, output_index)[source]

Hide one of the outputs of a component.

Parameters
  • component – The grasshopper component object, which can be accessed through the ghenv.Component call within Grasshopper API.

  • output_index – Integer for the index of the output to hide.

ladybug_rhino.grasshopper.is_user_admin()[source]

Get a Boolean for whether the current User has Admin access through Rhino.

ladybug_rhino.grasshopper.list_to_data_tree(input, root_count=0, s_type=<class 'object'>)[source]

Transform nested of lists or tuples to a Grasshopper DataTree.

Parameters
  • input – A nested list of lists to be converted into a data tree.

  • root_count – An integer for the starting path of the data tree.

  • s_type – An optional data type (eg. float, int, str) that defines all of the data in the data tree. The default (object) works will all data types but the conversion to data trees can be more efficient if a more specific type is specified.

ladybug_rhino.grasshopper.local_processor_count()[source]

Get an integer for the number of processors on this machine.

If, for whatever reason, the number of processors could not be sensed, None will be returned.

ladybug_rhino.grasshopper.longest_list(values, index)[source]

Get a value from a list while applying Grasshopper’s longest-list logic.

Parameters
  • values – An array of values from which a value will be pulled following longest list logic.

  • index – Integer for the index of the item in the list to return. If this index is greater than the length of the values, the last item of the list will be returned.

ladybug_rhino.grasshopper.merge_data_tree(data_trees, s_type=<class 'object'>)[source]

Merge a list of grasshopper DataTrees into a single DataTree.

Parameters
  • input – A list Grasshopper DataTrees to be merged into one.

  • s_type – An optional data type (eg. float, int, str) that defines all of the data in the data tree. The default (object) works will all data types but the conversion to data trees can be more efficient if a more specific type is specified.

ladybug_rhino.grasshopper.objectify_output(object_name, output_data)[source]

Wrap data into a single custom Python object that can later be de-serialized.

This is meant to address the same issue as the wrap_output method but it does so by simply hiding the individual items from the Grasshopper UI within a custom parent object that other components can accept as input and de-objectify to get access to the data. This strategy is also useful for the case of standard object types like integers where the large number of data points slows down the Grasshopper UI when they are output.

Parameters
  • object_name – Text for the name of the custom object that will wrap the data. This is how the object will display in the Grasshopper UI.

  • output_data – A list of data to be stored under the data property of the output object.

ladybug_rhino.grasshopper.recipe_result(result)[source]

Process a recipe result and handle the case that it’s a list of list.

Parameters

result – A recipe result to be processed.

ladybug_rhino.grasshopper.recommended_processor_count()[source]

Get an integer for the recommended number of processors for parallel calculation.

This should be one less than the number of processors available on this machine unless the machine has only one processor, in which case 1 will be returned. If, for whatever reason, the number of processors could not be sensed, a value of 1 will be returned.

ladybug_rhino.grasshopper.run_function_in_parallel(parallel_function, object_count, cpu_count=None)[source]

Run any function in parallel given a number of objects to be iterated over.

This method can run the calculation in a manner that targets a given CPU count and will also run the function normally (without the use of Tasks) if only one CPU is specified.

Parameters
  • parallel_function – A function which will be iterated over in a parallelized manner. This function should have a single input argument, which is the integer of the object to be simulated. Note that, in order for this function to be successfully parallelized, any lists of output data must be set up beforehand and this parallel_function should simply be replacing the data in this pre-created list.

  • object_count – An integer for the number of objects which will be iterated over in a parallelized manner.

  • cpu_count – An integer for the number of CPUs to be used in the intersection calculation. The ladybug_rhino.grasshopper.recommended_processor_count function can be used to get a recommendation. If set to None, all available processors will be used. (Default: None).

ladybug_rhino.grasshopper.schedule_solution(component, milliseconds)[source]

Schedule a new Grasshopper solution after a specified time interval.

Parameters
  • component – The grasshopper component object, which can be accessed through the ghenv.Component call within Grasshopper API.

  • milliseconds – Integer for the number of milliseconds after which the solution should happen.

ladybug_rhino.grasshopper.send_to_back(component)[source]

Send a component to the back of the canvas so that it is always executed first.

Parameters

component – The grasshopper component object, which can be accessed through the ghenv.Component call within Grasshopper API.

ladybug_rhino.grasshopper.set_sticky_variable(variable_name, value)[source]

Set a variable in sticky memory.

Parameters
  • variable_name – The name of the variable to set.

  • value – The value to set.

ladybug_rhino.grasshopper.show_output(component, output_index)[source]

Show one of the outputs of a component.

Parameters
  • component – The grasshopper component object, which can be accessed through the ghenv.Component call within Grasshopper API.

  • output_index – Integer for the index of the output to hide.

ladybug_rhino.grasshopper.turn_off_old_tag(component)[source]

Turn off the old tag that displays on GHPython components.

Parameters

component – The grasshopper component object, which can be accessed through the ghenv.Component call within Grasshopper API.

ladybug_rhino.grasshopper.unflatten_to_data_tree(all_data, pattern)[source]

Create DataTree from a single flattened list and a pattern.

Parameters
  • all_data – A flattened list of all data

  • pattern – A dictionary of patterns Pattern = namedtuple(‘Pattern’, ‘path index count’)

Returns

data_tree – A Grasshopper DataTree.

ladybug_rhino.grasshopper.wrap_output(output)[source]

Wrap Python objects as Grasshopper generic objects.

Passing output lists of Python objects through this function can greatly reduce the time needed to run the component since Grasshopper can spend a long time figuring out the object type is if it is not recognized. However, if the number of output objects is usually < 100, running this method won’t make a significant difference and so there’s no need to use it.

Parameters

output – A list of values to be wrapped as a generic Grasshopper Object (GOO).