Skip to content

Commit

Permalink
fix(organize): Expose the ability to filter rooms/faces by attribute
Browse files Browse the repository at this point in the history
  • Loading branch information
chriswmackey committed Feb 1, 2025
1 parent 4ba7ccc commit c5143ba
Show file tree
Hide file tree
Showing 8 changed files with 123 additions and 76 deletions.
Binary file modified honeybee_grasshopper_core/icon/HB Faces by Attribute.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified honeybee_grasshopper_core/icon/HB Rooms by Attribute.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
61 changes: 34 additions & 27 deletions honeybee_grasshopper_core/json/HB_Faces_by_Attribute.json
Original file line number Diff line number Diff line change
@@ -1,43 +1,50 @@
{
"version": "1.8.0",
"code": "\ntry: # import the core honeybee dependencies\n from honeybee.model import Model\n from honeybee.room import Room\n from honeybee.face import Face\n from honeybee.colorobj import ColorFace\nexcept ImportError as e:\n raise ImportError('\\nFailed to import honeybee:\\n\\t{}'.format(e))\n\ntry: # import the ladybug_{{cad}} dependencies\n \n from ladybug_{{cad}}.{{plugin}} import all_required_inputs, list_to_data_tree\nexcept ImportError as e:\n raise ImportError('\\nFailed to import ladybug_{{cad}}:\\n\\t{}'.format(e))\n\n\nif all_required_inputs(ghenv.Component):\n # extract any faces from input Rooms or Models\n faces = []\n for hb_obj in _hb_objs:\n if isinstance(hb_obj, Room):\n faces.extend(hb_obj.faces)\n faces.extend(hb_obj.shades)\n elif isinstance(hb_obj, Room):\n faces.append(hb_obj)\n elif isinstance(hb_obj, Model):\n for room in hb_obj.rooms:\n faces.extend(room.faces)\n faces.extend(room.shades)\n faces.extend(hb_obj.orphaned_faces)\n faces.extend(hb_obj.orphaned_apertures)\n faces.extend(hb_obj.orphaned_doors)\n faces.extend(hb_obj.orphaned_shades)\n faces.extend(hb_obj.shade_meshes)\n else:\n msg = 'Expected Face, Room or Model. Got {}.'.format(type(hb_obj))\n raise TypeError(msg)\n\n # use the ColorFace object to get a set of attributes assigned to the faces\n color_obj = ColorFace(faces, _attribute)\n\n # loop through each of the hb_objs and get the attribute\n if len(value_) == 0:\n values = color_obj.attributes_unique\n hb_objs = [[] for val in values]\n for atr, face in zip(color_obj.attributes, color_obj.flat_faces):\n atr_i = values.index(atr)\n hb_objs[atr_i].append(face)\n else:\n values = [atr for atr in color_obj.attributes_unique if atr in value_]\n hb_objs = [[] for val in values]\n for atr, face in zip(color_obj.attributes, color_obj.flat_faces):\n if atr in values:\n atr_i = values.index(atr)\n hb_objs[atr_i].append(face)\n hb_objs = list_to_data_tree(hb_objs)\n",
"category": "Honeybee",
"inputs": [
{
"type": "System.Object",
"name": "_hb_objs",
"access": "list",
"default": null,
"description": "An array of honeybee Rooms, Faces, Apertures, Doors or Shades\nto be separated by their attributes in the Rhino scene."
},
{
"type": "string",
"name": "_attribute",
"access": "item",
"default": null,
"description": "Text for the name of the Face attribute with which the\nFaces should be labeled. The Honeybee \"Face Attributes\" component\nlists all of the core attributes of the room. Also, each Honeybee\nextension (ie. Radiance, Energy) includes its own component that\nlists the Face attributes of that extension."
},
{
"type": "System.Object",
"name": "value_",
"access": "list",
"default": null,
"description": "An optional value of the attribute that can be used to filter\nthe output rooms. For example, if the input attribute is \"Azimuth\"\na value for the orientation of the Face can be plugged in here\n(eg. \"180\" for south-facing) in order to get Faces with only\nthis oreintation."
}
],
"nickname": "FacesByAttr",
"version": "1.8.1",
"outputs": [
[
{
"access": "None",
"name": "values",
"description": "A list of values with one attribute value for each branch of the\noutput hb_objs.",
"type": null,
"default": null
"name": "values",
"access": "None",
"default": null,
"description": "A list of values with one attribute value for each branch of the\noutput hb_objs."
},
{
"access": "None",
"name": "hb_objs",
"description": "A data tree of honeybee faces and sub-faces with each branc\nof the tree representing a different attribute value.",
"type": null,
"default": null
"name": "hb_objs",
"access": "None",
"default": null,
"description": "A data tree of honeybee faces and sub-faces with each branc\nof the tree representing a different attribute value."
}
]
],
"inputs": [
{
"access": "list",
"name": "_hb_objs",
"description": "An array of honeybee Rooms, Faces, Apertures, Doors or Shades\nto be separated by their attributes in the Rhino scene.",
"type": "System.Object",
"default": null
},
{
"access": "item",
"name": "_attribute",
"description": "Text for the name of the Face attribute with which the\nFaces should be labeled. The Honeybee \"Face Attributes\" component\nlists all of the core attributes of the room. Also, each Honeybee\nextension (ie. Radiance, Energy) includes its own component that\nlists the Face attributes of that extension.",
"type": "string",
"default": null
}
],
"subcategory": "2 :: Organize",
"code": "\ntry: # import the core honeybee dependencies\n from honeybee.model import Model\n from honeybee.room import Room\n from honeybee.colorobj import ColorFace\nexcept ImportError as e:\n raise ImportError('\\nFailed to import honeybee:\\n\\t{}'.format(e))\n\ntry: # import the ladybug_{{cad}} dependencies\n \n from ladybug_{{cad}}.{{plugin}} import all_required_inputs, list_to_data_tree\nexcept ImportError as e:\n raise ImportError('\\nFailed to import ladybug_{{cad}}:\\n\\t{}'.format(e))\n\n\nif all_required_inputs(ghenv.Component):\n # extract any faces from input Rooms or Models\n faces = []\n for hb_obj in _hb_objs:\n if isinstance(hb_obj, Model):\n for room in hb_obj.rooms:\n faces.extend(room.faces)\n faces.extend(room.shades)\n faces.extend(hb_obj.orphaned_faces)\n faces.extend(hb_obj.orphaned_apertures)\n faces.extend(hb_obj.orphaned_doors)\n faces.extend(hb_obj.orphaned_shades)\n faces.extend(hb_obj.shade_meshes)\n elif isinstance(hb_obj, Room):\n faces.extend(hb_obj.faces)\n faces.extend(hb_obj.shades)\n else:\n faces.append(hb_obj)\n\n # use the ColorRoom object to get a set of attributes assigned to the faces\n color_obj = ColorFace(faces, _attribute)\n values = color_obj.attributes_unique\n\n # loop through each of the hb_objs and get the floor height\n hb_objs = [[] for val in values]\n for atr, face in zip(color_obj.attributes, color_obj.flat_faces):\n atr_i = values.index(atr)\n hb_objs[atr_i].append(face)\n hb_objs = list_to_data_tree(hb_objs)\n",
"category": "Honeybee",
"name": "HB Faces by Attribute",
"description": "Separate and group Honeybee Faces, Apertures, Doors and Shades by any attribute\nthat the objects possess.\n_\nThis can be used to group faces by construction, modifier, etc.\n-"
}
61 changes: 34 additions & 27 deletions honeybee_grasshopper_core/json/HB_Rooms_by_Attribute.json
Original file line number Diff line number Diff line change
@@ -1,43 +1,50 @@
{
"version": "1.8.0",
"code": "\ntry: # import the core honeybee dependencies\n from honeybee.model import Model\n from honeybee.room import Room\n from honeybee.colorobj import ColorRoom\nexcept ImportError as e:\n raise ImportError('\\nFailed to import honeybee:\\n\\t{}'.format(e))\n\ntry: # import the ladybug_{{cad}} dependencies\n \n from ladybug_{{cad}}.{{plugin}} import all_required_inputs, list_to_data_tree\nexcept ImportError as e:\n raise ImportError('\\nFailed to import ladybug_{{cad}}:\\n\\t{}'.format(e))\n\n\nif all_required_inputs(ghenv.Component):\n # extract any rooms from input Models\n in_rooms = []\n for hb_obj in _rooms:\n if isinstance(hb_obj, Room):\n in_rooms.append(hb_obj)\n elif isinstance(hb_obj, Model):\n in_rooms.extend(hb_obj.rooms)\n else:\n raise TypeError('Expected Room or Model. Got {}.'.format(type(hb_obj)))\n\n # use the ColorRoom object to get a set of attributes assigned to the rooms\n color_obj = ColorRoom(in_rooms, _attribute)\n\n # loop through each of the rooms and get the attributes\n if len(value_) == 0:\n values = color_obj.attributes_unique\n rooms = [[] for val in values]\n for atr, room in zip(color_obj.attributes, in_rooms):\n atr_i = values.index(atr)\n rooms[atr_i].append(room)\n else:\n values = [atr for atr in color_obj.attributes_unique if atr in value_]\n rooms = [[] for val in values]\n for atr, room in zip(color_obj.attributes, in_rooms):\n if atr in values:\n atr_i = values.index(atr)\n rooms[atr_i].append(room)\n rooms = list_to_data_tree(rooms)\n",
"category": "Honeybee",
"inputs": [
{
"type": "System.Object",
"name": "_rooms",
"access": "list",
"default": null,
"description": "An array of honeybee Rooms or honeybee Models to be separated\nand grouped based on their attributes."
},
{
"type": "string",
"name": "_attribute",
"access": "item",
"default": null,
"description": "Text for the name of the Room attribute with which the\nRooms should be labeled. The Honeybee \"Room Attributes\" component\nlists all of the core attributes of the room. Also, each Honeybee\nextension (ie. Radiance, Energy) includes its own component that\nlists the Room attributes of that extension."
},
{
"type": "string",
"name": "value_",
"access": "list",
"default": null,
"description": "An optional value of the attribute that can be used to filter\nthe output rooms. For example, if the input attribute is \"Program\"\na value for the name of a program can be plugged in here\n(eg. \"2019::LargeOffice::OpenOffice\") in order to get only the\nrooms that have this program assigned."
}
],
"nickname": "RoomsByAttr",
"version": "1.8.1",
"outputs": [
[
{
"access": "None",
"name": "values",
"description": "A list of values with one attribute value for each branch of the\noutput rooms.",
"type": null,
"default": null
"name": "values",
"access": "None",
"default": null,
"description": "A list of values with one attribute value for each branch of the\noutput rooms."
},
{
"access": "None",
"name": "rooms",
"description": "A data tree of honeybee rooms with each branch of the tree\nrepresenting a different attribute value.",
"type": null,
"default": null
"name": "rooms",
"access": "None",
"default": null,
"description": "A data tree of honeybee rooms with each branch of the tree\nrepresenting a different attribute value."
}
]
],
"inputs": [
{
"access": "list",
"name": "_rooms",
"description": "An array of honeybee Rooms or honeybee Models to be separated\nand grouped based on their attributes.",
"type": "System.Object",
"default": null
},
{
"access": "item",
"name": "_attribute",
"description": "Text for the name of the Room attribute with which the\nRooms should be labeled. The Honeybee \"Room Attributes\" component\nlists all of the core attributes of the room. Also, each Honeybee\nextension (ie. Radiance, Energy) includes its own component that\nlists the Room attributes of that extension.",
"type": "string",
"default": null
}
],
"subcategory": "2 :: Organize",
"code": "\ntry: # import the core honeybee dependencies\n from honeybee.model import Model\n from honeybee.colorobj import ColorRoom\nexcept ImportError as e:\n raise ImportError('\\nFailed to import honeybee:\\n\\t{}'.format(e))\n\ntry: # import the ladybug_{{cad}} dependencies\n \n from ladybug_{{cad}}.{{plugin}} import all_required_inputs, list_to_data_tree\nexcept ImportError as e:\n raise ImportError('\\nFailed to import ladybug_{{cad}}:\\n\\t{}'.format(e))\n\n\nif all_required_inputs(ghenv.Component):\n # extract any rooms from input Models\n in_rooms = []\n for hb_obj in _rooms:\n if isinstance(hb_obj, Model):\n in_rooms.extend(hb_obj.rooms)\n else:\n in_rooms.append(hb_obj)\n\n # use the ColorRoom object to get a set of attributes assigned to the rooms\n color_obj = ColorRoom(in_rooms, _attribute)\n values = color_obj.attributes_unique\n\n # loop through each of the rooms and get the attributes\n rooms = [[] for val in values]\n for atr, room in zip(color_obj.attributes, in_rooms):\n atr_i = values.index(atr)\n rooms[atr_i].append(room)\n rooms = list_to_data_tree(rooms)\n",
"category": "Honeybee",
"name": "HB Rooms by Attribute",
"description": "Separate and group honeybee Rooms by any attribute that the room possesses.\n_\nThis can be used to group rooms by program, whether rooms are conditioned, etc.\n-"
}
43 changes: 30 additions & 13 deletions honeybee_grasshopper_core/src/HB Faces by Attribute.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,11 @@
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.
value_: An optional value of the attribute that can be used to filter
the output rooms. For example, if the input attribute is "Azimuth"
a value for the orientation of the Face can be plugged in here
(eg. "180" for south-facing) in order to get Faces with only
this oreintation.
Returns:
values: A list of values with one attribute value for each branch of the
Expand All @@ -32,14 +37,15 @@

ghenv.Component.Name = "HB Faces by Attribute"
ghenv.Component.NickName = 'FacesByAttr'
ghenv.Component.Message = '1.8.0'
ghenv.Component.Message = '1.8.1'
ghenv.Component.Category = 'Honeybee'
ghenv.Component.SubCategory = '2 :: Organize'
ghenv.Component.AdditionalHelpFromDocStrings = '1'

try: # import the core honeybee dependencies
from honeybee.model import Model
from honeybee.room import Room
from honeybee.face import Face
from honeybee.colorobj import ColorFace
except ImportError as e:
raise ImportError('\nFailed to import honeybee:\n\t{}'.format(e))
Expand All @@ -55,7 +61,12 @@
# extract any faces from input Rooms or Models
faces = []
for hb_obj in _hb_objs:
if isinstance(hb_obj, Model):
if isinstance(hb_obj, Room):
faces.extend(hb_obj.faces)
faces.extend(hb_obj.shades)
elif isinstance(hb_obj, Room):
faces.append(hb_obj)
elif isinstance(hb_obj, Model):
for room in hb_obj.rooms:
faces.extend(room.faces)
faces.extend(room.shades)
Expand All @@ -64,19 +75,25 @@
faces.extend(hb_obj.orphaned_doors)
faces.extend(hb_obj.orphaned_shades)
faces.extend(hb_obj.shade_meshes)
elif isinstance(hb_obj, Room):
faces.extend(hb_obj.faces)
faces.extend(hb_obj.shades)
else:
faces.append(hb_obj)
msg = 'Expected Face, Room or Model. Got {}.'.format(type(hb_obj))
raise TypeError(msg)

# use the ColorRoom object to get a set of attributes assigned to the faces
# use the ColorFace 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)
# loop through each of the hb_objs and get the attribute
if len(value_) == 0:
values = color_obj.attributes_unique
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)
else:
values = [atr for atr in color_obj.attributes_unique if atr in value_]
hb_objs = [[] for val in values]
for atr, face in zip(color_obj.attributes, color_obj.flat_faces):
if atr in values:
atr_i = values.index(atr)
hb_objs[atr_i].append(face)
hb_objs = list_to_data_tree(hb_objs)
34 changes: 25 additions & 9 deletions honeybee_grasshopper_core/src/HB Rooms by Attribute.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,12 @@
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.
value_: An optional value of the attribute that can be used to filter
the output rooms. For example, if the input attribute is "Program"
a value for the name of a program can be plugged in here
(eg. "2019::LargeOffice::OpenOffice") in order to get only the
rooms that have this program assigned.
Returns:
values: A list of values with one attribute value for each branch of the
output rooms.
Expand All @@ -31,13 +36,14 @@

ghenv.Component.Name = "HB Rooms by Attribute"
ghenv.Component.NickName = 'RoomsByAttr'
ghenv.Component.Message = '1.8.0'
ghenv.Component.Message = '1.8.1'
ghenv.Component.Category = 'Honeybee'
ghenv.Component.SubCategory = '2 :: Organize'
ghenv.Component.AdditionalHelpFromDocStrings = '1'

try: # import the core honeybee dependencies
from honeybee.model import Model
from honeybee.room import Room
from honeybee.colorobj import ColorRoom
except ImportError as e:
raise ImportError('\nFailed to import honeybee:\n\t{}'.format(e))
Expand All @@ -53,18 +59,28 @@
# extract any rooms from input Models
in_rooms = []
for hb_obj in _rooms:
if isinstance(hb_obj, Model):
if isinstance(hb_obj, Room):
in_rooms.append(hb_obj)
elif isinstance(hb_obj, Model):
in_rooms.extend(hb_obj.rooms)
else:
in_rooms.append(hb_obj)
raise TypeError('Expected Room or Model. Got {}.'.format(type(hb_obj)))

# use the ColorRoom object to get a set of attributes assigned to the rooms
color_obj = ColorRoom(in_rooms, _attribute)
values = color_obj.attributes_unique

# loop through each of the rooms and get the attributes
rooms = [[] for val in values]
for atr, room in zip(color_obj.attributes, in_rooms):
atr_i = values.index(atr)
rooms[atr_i].append(room)
if len(value_) == 0:
values = color_obj.attributes_unique
rooms = [[] for val in values]
for atr, room in zip(color_obj.attributes, in_rooms):
atr_i = values.index(atr)
rooms[atr_i].append(room)
else:
values = [atr for atr in color_obj.attributes_unique if atr in value_]
rooms = [[] for val in values]
for atr, room in zip(color_obj.attributes, in_rooms):
if atr in values:
atr_i = values.index(atr)
rooms[atr_i].append(room)
rooms = list_to_data_tree(rooms)
Binary file modified honeybee_grasshopper_core/user_objects/HB Faces by Attribute.ghuser
Binary file not shown.
Binary file modified honeybee_grasshopper_core/user_objects/HB Rooms by Attribute.ghuser
Binary file not shown.

0 comments on commit c5143ba

Please sign in to comment.