-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(organize): Add components to organize rooms/faces by attribute
This commit adds components to organize honeybee Rooms and Faces by any attribute. It also includes components to do specific types of common organization (like rooms by floor height or orientation).
- Loading branch information
1 parent
752718e
commit eb7ab42
Showing
19 changed files
with
372 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
# Honeybee: A Plugin for Environmental Analysis (GPL) | ||
# This file is part of Honeybee. | ||
# | ||
# Copyright (c) 2019, Ladybug Tools. | ||
# You should have received a copy of the GNU General Public License | ||
# along with Honeybee; If not, see <http://www.gnu.org/licenses/>. | ||
# | ||
# @license GPL-3.0+ <http://spdx.org/licenses/GPL-3.0+> | ||
|
||
""" | ||
Change the display name and identifier of this object and all child objects by | ||
inserting a prefix. | ||
_ | ||
This is particularly useful in workflows where you duplicate and edit | ||
a starting object and then want to combine it with the original object | ||
into one Model (like making a model of repeated rooms) since all objects | ||
within a Model must have unique identifiers. | ||
- | ||
Args: | ||
_hb_objs: A Honeybee Room, Face, Shade, Aperture, or Door to which a | ||
prefix should be added to its name. | ||
_prefix: Text that will be inserted at the start of this object's | ||
(and child objects') identifier and display_name. This will also be | ||
added to any Surface boundary conditions of Faces, Apertures, or | ||
Doors. It is recommended that this prefix be short to avoid maxing | ||
out the 100 allowable characters for honeybee identifiers. This can | ||
also be a list of prefixes that correspond to the input _hb_objs | ||
Returns: | ||
report: ... | ||
hb_objs: The input Honeybee objects with a prefix added to their display | ||
names and identifiers. | ||
""" | ||
|
||
ghenv.Component.Name = "HB Add Prefix" | ||
ghenv.Component.NickName = 'Prefix' | ||
ghenv.Component.Message = '0.1.0' | ||
ghenv.Component.Category = 'Honeybee' | ||
ghenv.Component.SubCategory = '0 :: Create' | ||
ghenv.Component.AdditionalHelpFromDocStrings = '0' | ||
|
||
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): | ||
hb_objs = [] | ||
for i, obj in enumerate(_hb_objs): | ||
obj_dup = obj.duplicate() | ||
try: | ||
prefix = _prefix[i] | ||
except IndexError: | ||
prefix = _prefix[-1] | ||
obj_dup.add_prefix(prefix) | ||
hb_objs.append(obj_dup) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
# Honeybee: A Plugin for Environmental Analysis (GPL) | ||
# This file is part of Honeybee. | ||
# | ||
# Copyright (c) 2019, Ladybug Tools. | ||
# You should have received a copy of the GNU General Public License | ||
# along with Honeybee; If not, see <http://www.gnu.org/licenses/>. | ||
# | ||
# @license GPL-3.0+ <http://spdx.org/licenses/GPL-3.0+> | ||
|
||
""" | ||
Separate and group Honeybee Faces, Apertures, Doors and Shades by any attribute | ||
that the objects possess. | ||
_ | ||
This can be used to group faces by construction, modifier, etc. | ||
- | ||
Args: | ||
_hb_objs: An array of honeybee Rooms, Faces, Apertures, Doors or Shades | ||
to be colored with their attributes in the Rhino scene. | ||
_attribute: Text for the name of the Face attribute with which the | ||
Faces should be labeled. The Honeybee "Face Attributes" component | ||
lists all of the core attributes of the room. Also, each Honeybee | ||
extension (ie. Radiance, Energy) includes its own component that | ||
lists the Face attributes of that extension. | ||
Returns: | ||
values: A list of values with one attribute value for each branch of the | ||
output hb_objs. | ||
hb_objs: A data tree of honeybee faces and sub-faces with each branc | ||
of the tree representing a different attribute value. | ||
""" | ||
|
||
ghenv.Component.Name = "HB Faces by Attribute" | ||
ghenv.Component.NickName = 'FacesByAttr' | ||
ghenv.Component.Message = '0.1.0' | ||
ghenv.Component.Category = 'Honeybee' | ||
ghenv.Component.SubCategory = '2 :: Organize' | ||
ghenv.Component.AdditionalHelpFromDocStrings = '1' | ||
|
||
try: # import the core honeybee dependencies | ||
from honeybee.room import Room | ||
from honeybee.colorobj import ColorFace | ||
except ImportError as e: | ||
raise ImportError('\nFailed to import honeybee:\n\t{}'.format(e)) | ||
|
||
try: # import the ladybug_rhino dependencies | ||
|
||
from ladybug_rhino.grasshopper import all_required_inputs, list_to_data_tree | ||
except ImportError as e: | ||
raise ImportError('\nFailed to import ladybug_rhino:\n\t{}'.format(e)) | ||
|
||
|
||
if all_required_inputs(ghenv.Component): | ||
# extract any faces from input Rooms or Models | ||
faces = [] | ||
for hb_obj in _hb_objs: | ||
if isinstance(hb_obj, Room): | ||
faces.extend(hb_obj.faces) | ||
faces.extend(hb_obj.shades) | ||
else: | ||
faces.append(hb_obj) | ||
|
||
# use the ColorRoom object to get a set of attributes assigned to the faces | ||
color_obj = ColorFace(faces, _attribute) | ||
values = color_obj.attributes_unique | ||
|
||
# loop through each of the hb_objs and get the floor height | ||
hb_objs = [[] for val in values] | ||
for atr, face in zip(color_obj.attributes, color_obj.flat_faces): | ||
atr_i = values.index(atr) | ||
hb_objs[atr_i].append(face) | ||
hb_objs = list_to_data_tree(hb_objs) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
# Honeybee: A Plugin for Environmental Analysis (GPL) | ||
# This file is part of Honeybee. | ||
# | ||
# Copyright (c) 2019, Ladybug Tools. | ||
# You should have received a copy of the GNU General Public License | ||
# along with Honeybee; If not, see <http://www.gnu.org/licenses/>. | ||
# | ||
# @license GPL-3.0+ <http://spdx.org/licenses/GPL-3.0+> | ||
|
||
""" | ||
Separate and group honeybee Rooms by any attribute that the room possesses. | ||
_ | ||
This can be used to group rooms by program, whether rooms are conditioned, etc. | ||
- | ||
Args: | ||
_rooms: An array of honeybee Rooms to be separated and grouped based | ||
on their attributes. | ||
_attribute: Text for the name of the Room attribute with which the | ||
Rooms should be labeled. The Honeybee "Room Attributes" component | ||
lists all of the core attributes of the room. Also, each Honeybee | ||
extension (ie. Radiance, Energy) includes its own component that | ||
lists the Room attributes of that extension. | ||
Returns: | ||
values: A list of values with one attribute value for each branch of the | ||
output rooms. | ||
rooms: A data tree of honeybee rooms with each branch of the tree | ||
representing a different attribute value. | ||
""" | ||
|
||
ghenv.Component.Name = "HB Rooms by Attribute" | ||
ghenv.Component.NickName = 'RoomsByAttr' | ||
ghenv.Component.Message = '0.1.0' | ||
ghenv.Component.Category = 'Honeybee' | ||
ghenv.Component.SubCategory = '2 :: Organize' | ||
ghenv.Component.AdditionalHelpFromDocStrings = '1' | ||
|
||
try: # import the core honeybee dependencies | ||
from honeybee.colorobj import ColorRoom | ||
except ImportError as e: | ||
raise ImportError('\nFailed to import honeybee:\n\t{}'.format(e)) | ||
|
||
try: # import the ladybug_rhino dependencies | ||
|
||
from ladybug_rhino.grasshopper import all_required_inputs, list_to_data_tree | ||
except ImportError as e: | ||
raise ImportError('\nFailed to import ladybug_rhino:\n\t{}'.format(e)) | ||
|
||
|
||
if all_required_inputs(ghenv.Component): | ||
# use the ColorRoom object to get a set of attributes assigned to the rooms | ||
color_obj = ColorRoom(_rooms, _attribute) | ||
values = color_obj.attributes_unique | ||
|
||
# loop through each of the rooms and get the floor height | ||
rooms = [[] for val in values] | ||
for atr, room in zip(color_obj.attributes, _rooms): | ||
atr_i = values.index(atr) | ||
rooms[atr_i].append(room) | ||
rooms = list_to_data_tree(rooms) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
# Honeybee: A Plugin for Environmental Analysis (GPL) | ||
# This file is part of Honeybee. | ||
# | ||
# Copyright (c) 2019, Ladybug Tools. | ||
# You should have received a copy of the GNU General Public License | ||
# along with Honeybee; If not, see <http://www.gnu.org/licenses/>. | ||
# | ||
# @license GPL-3.0+ <http://spdx.org/licenses/GPL-3.0+> | ||
|
||
""" | ||
Separate and group honeybee rooms with the same average floor height. | ||
- | ||
Args: | ||
_rooms: A list of honeybee rooms to be separated by floor height. | ||
min_diff_: An optional float value to denote the minimum difference | ||
in floor heights that is considered meaningful. This can be used | ||
to ensure rooms like those representing stair landings are grouped | ||
with floors. If None, any difference in floor heights greater than | ||
the Rhino model tolerance will be considered meaningful. | ||
Returns: | ||
flr_hgts: A list of floor heights with one floor height for each branch | ||
of the output rooms. | ||
rooms: A data tree of honeybee rooms with each branch of the tree | ||
representing a different floor height. | ||
""" | ||
|
||
|
||
ghenv.Component.Name = "HB Rooms by Floor Height" | ||
ghenv.Component.NickName = 'FloorHeight' | ||
ghenv.Component.Message = '0.1.0' | ||
ghenv.Component.Category = 'Honeybee' | ||
ghenv.Component.SubCategory = '2 :: Organize' | ||
ghenv.Component.AdditionalHelpFromDocStrings = '2' | ||
|
||
try: # import the ladybug_rhino dependencies | ||
from ladybug_rhino.config import tolerance | ||
from ladybug_rhino.grasshopper import all_required_inputs, list_to_data_tree | ||
except ImportError as e: | ||
raise ImportError('\nFailed to import ladybug_rhino:\n\t{}'.format(e)) | ||
|
||
|
||
if all_required_inputs(ghenv.Component): | ||
# loop through each of the rooms and get the floor height | ||
flrhgt_dict = {} | ||
for room in _rooms: | ||
flrhgt = room.average_floor_height | ||
try: | ||
flrhgt_dict[flrhgt].append(room) | ||
except KeyError: | ||
flrhgt_dict[flrhgt] = [] | ||
flrhgt_dict[flrhgt].append(room) | ||
|
||
# sort the rooms by floor heights | ||
room_mtx = sorted(flrhgt_dict.items(), key = lambda d: float(d[0])) | ||
flr_hgts = [r_tup[0] for r_tup in room_mtx] | ||
rooms = [r_tup[1] for r_tup in room_mtx] | ||
|
||
# group floor heights if they differ by less than the min_diff | ||
min_diff = tolerance if min_diff_ is None else min_diff_ | ||
new_flr_hgts = [flr_hgts[0]] | ||
new_rooms = [rooms[0]] | ||
for flrh, rm in zip(flr_hgts[1:], rooms[1:]): | ||
if flrh - new_flr_hgts[-1] < min_diff: | ||
new_rooms[-1].extend(rm) | ||
else: | ||
new_rooms.append(rm) | ||
new_flr_hgts.append(flrh) | ||
flr_hgts = new_flr_hgts | ||
rooms = new_rooms | ||
|
||
# convert matrix to data tree | ||
rooms = list_to_data_tree(rooms) |
Oops, something went wrong.