/
HB Apply ModifierSet.py
71 lines (59 loc) · 2.45 KB
/
HB Apply ModifierSet.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
# Honeybee: A Plugin for Environmental Analysis (GPL)
# This file is part of Honeybee.
#
# Copyright (c) 2024, Ladybug Tools.
# You should have received a copy of the GNU Affero General Public License
# along with Honeybee; If not, see <http://www.gnu.org/licenses/>.
#
# @license AGPL-3.0-or-later <https://spdx.org/licenses/AGPL-3.0-or-later>
"""
Apply ModifierSet to Honeybee Rooms.
-
Args:
_rooms: Honeybee Rooms to which the input _mod_set should be assigned.
This can also be a Honeybee Model for which all Rooms
will be assigned the ModifierSet.
_mod_set: A Honeybee ModifierSet to be applied to the input _room.
This can also be text for a modifier set to be looked up in the
modifier set library.
Returns:
rooms: The input Rooms with their modifier sets edited.
"""
ghenv.Component.Name = 'HB Apply ModifierSet'
ghenv.Component.NickName = 'ApplyModSet'
ghenv.Component.Message = '1.8.0'
ghenv.Component.Category = 'HB-Radiance'
ghenv.Component.SubCategory = '1 :: Modifiers'
ghenv.Component.AdditionalHelpFromDocStrings = '6'
try: # import the honeybee extension
from honeybee.model import Model
from honeybee.room import Room
except ImportError as e:
raise ImportError('\nFailed to import honeybee:\n\t{}'.format(e))
try: # import the honeybee-radiance extension
from honeybee_radiance.lib.modifiersets import modifier_set_by_identifier
except ImportError as e:
raise ImportError('\nFailed to import honeybee_radiance:\n\t{}'.format(e))
try: # import the ladybug_rhino dependencies
from ladybug_rhino.grasshopper import all_required_inputs
except ImportError as e:
raise ImportError('\nFailed to import ladybug_rhino:\n\t{}'.format(e))
if all_required_inputs(ghenv.Component):
# duplicate the initial objects
rooms = [obj.duplicate() for obj in _rooms]
# extract any rooms from the input Models
hb_objs = []
for hb_obj in rooms:
if isinstance(hb_obj, Model):
hb_objs.extend(hb_obj.rooms)
elif isinstance(hb_obj, Room):
hb_objs.append(hb_obj)
else:
raise ValueError(
'Expected Honeybee Room or Model. Got {}.'.format(type(hb_obj)))
# process the input modifier set if it's a string
if isinstance(_mod_set, str):
_mod_set = modifier_set_by_identifier(_mod_set)
# assign the modifier set
for rm in hb_objs:
rm.properties.radiance.modifier_set = _mod_set