|
| 1 | +# Ladybug: A Plugin for Environmental Analysis (GPL) |
| 2 | +# This file is part of Ladybug. |
| 3 | +# |
| 4 | +# Copyright (c) 2023, Ladybug Tools. |
| 5 | +# You should have received a copy of the GNU Affero General Public License |
| 6 | +# along with Ladybug; If not, see <http://www.gnu.org/licenses/>. |
| 7 | +# |
| 8 | +# @license AGPL-3.0-or-later <https://spdx.org/licenses/AGPL-3.0-or-later> |
| 9 | + |
| 10 | +""" |
| 11 | +Drop suggested Ladybug Tools components into a Grasshopper file for every |
| 12 | +Legacy Ladybug + Honeybee component on the canvas. |
| 13 | +- |
| 14 | +All existing LBT and native Grasshopper components will be left as they are and |
| 15 | +only the Legacy components will be circled in Red and have the suggested LBT |
| 16 | +component placed next to them (if applicable). Note that, after this component |
| 17 | +runs, you must then connect the new LBT components to the others and delete the |
| 18 | +Legacy components. |
| 19 | +- |
| 20 | +Where applicable, each red circle will have a message about how the LBT component |
| 21 | +differs from the Legacy one or if there may be a more appropirate LBT component |
| 22 | +in the future. Also note that some Legacy workflows have been heavily refactored |
| 23 | +since Legacy, meaning a different number of components may be necessary to achieve |
| 24 | +the same thing (typically fewer in LBT than Legacy, meaning some LEgacy components |
| 25 | +should be deleted without replacement). |
| 26 | +- |
| 27 | +
|
| 28 | + Args: |
| 29 | + _update: Set to "True" to have this component to search through the current |
| 30 | + Grasshopper file and drop suggested Ladybug Tools components |
| 31 | + for every Legacy Ladybug + Honeybee component on the canvas. |
| 32 | +
|
| 33 | + Returns: |
| 34 | + report: Errors, warnings, etc. |
| 35 | +""" |
| 36 | + |
| 37 | +ghenv.Component.Name = 'LB Legacy Updater' |
| 38 | +ghenv.Component.NickName = 'Legacy' |
| 39 | +ghenv.Component.Message = '1.7.0' |
| 40 | +ghenv.Component.Category = 'Ladybug' |
| 41 | +ghenv.Component.SubCategory = '5 :: Version' |
| 42 | +ghenv.Component.AdditionalHelpFromDocStrings = '0' |
| 43 | + |
| 44 | +try: |
| 45 | + from ladybug_rhino.versioning.gather import gather_canvas_components |
| 46 | + from ladybug_rhino.versioning.legacy import suggest_new_component |
| 47 | + from ladybug_rhino.grasshopper import all_required_inputs, give_warning |
| 48 | +except ImportError as e: |
| 49 | + raise ImportError('\nFailed to import ladybug_rhino:\n\t{}'.format(e)) |
| 50 | + |
| 51 | + |
| 52 | +if all_required_inputs(ghenv.Component) and _update: |
| 53 | + # load all of the GHPython userobjects and update the versions |
| 54 | + components = gather_canvas_components(ghenv.Component) |
| 55 | + report_init = [] |
| 56 | + for comp in components: |
| 57 | + try: |
| 58 | + report_init.append(suggest_new_component(comp, ghenv.Component)) |
| 59 | + except Exception: |
| 60 | + if hasattr(comp, 'Name'): |
| 61 | + msg = 'Failed to Update "{}"'.format(comp.Name) |
| 62 | + print(msg) |
| 63 | + give_warning(ghenv.Component, msg) |
| 64 | + print('\n'.join(r for r in report_init if r)) |
0 commit comments