Skip to content

Commit 4b1eea4

Browse files
chriswmackeyChris Mackey
authored andcommitted
feat(version): Add a component to assist with update from Legacy
1 parent 3386cf4 commit 4b1eea4

File tree

7 files changed

+85
-114
lines changed

7 files changed

+85
-114
lines changed

ladybug_grasshopper/json/LB_Data_to_Legacy.json

Lines changed: 0 additions & 29 deletions
This file was deleted.
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
{
2+
"version": "1.7.0",
3+
"nickname": "Legacy",
4+
"outputs": [
5+
[]
6+
],
7+
"inputs": [
8+
{
9+
"access": "item",
10+
"name": "_update",
11+
"description": "Set to \"True\" to have this component to search through the current\nGrasshopper file and drop suggested Ladybug Tools components\nfor every Legacy Ladybug + Honeybee component on the canvas.",
12+
"type": "System.Object",
13+
"default": null
14+
}
15+
],
16+
"subcategory": "5 :: Version",
17+
"code": "\ntry:\n from ladybug_{{cad}}.versioning.gather import gather_canvas_components\n from ladybug_{{cad}}.versioning.legacy import suggest_new_component\n from ladybug_{{cad}}.{{plugin}} import all_required_inputs, give_warning\nexcept ImportError as e:\n raise ImportError('\\nFailed to import ladybug_{{cad}}:\\n\\t{}'.format(e))\n\n\nif all_required_inputs(ghenv.Component) and _update:\n # load all of the {{PLGN}}Python userobjects and update the versions\n components = gather_canvas_components(ghenv.Component)\n report_init = []\n for comp in components:\n try:\n report_init.append(suggest_new_component(comp, ghenv.Component))\n except Exception:\n if hasattr(comp, 'Name'):\n msg = 'Failed to Update \"{}\"'.format(comp.Name)\n print(msg)\n give_warning(ghenv.Component, msg)\n print('\\n'.join(r for r in report_init if r))\n",
18+
"category": "Ladybug",
19+
"name": "LB Legacy Updater",
20+
"description": "Drop suggested Ladybug Tools components into a Grasshopper file for every\nLegacy Ladybug + Honeybee component on the canvas.\n-\nAll existing LBT and native Grasshopper components will be left as they are and\nonly the Legacy components will be circled in Red and have the suggested LBT\ncomponent placed next to them (if applicable). Note that, after this component\nruns, you must then connect the new LBT components to the others and delete the\nLegacy components.\n-\nWhere applicable, each red circle will have a message about how the LBT component\ndiffers from the Legacy one or if there may be a more appropirate LBT component\nin the future. Also note that some Legacy workflows have been heavily refactored\nsince Legacy, meaning a different number of components may be necessary to achieve\nthe same thing (typically fewer in LBT than Legacy, meaning some LEgacy components\nshould be deleted without replacement).\n-"
21+
}

ladybug_grasshopper/src/LB Data to Legacy.py

Lines changed: 0 additions & 85 deletions
This file was deleted.
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
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))
-3.83 KB
Binary file not shown.
4.41 KB
Binary file not shown.

0 commit comments

Comments
 (0)