Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(create): Add a component to join small rooms together #297

Merged
merged 1 commit into from
Oct 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
36 changes: 36 additions & 0 deletions dragonfly_grasshopper/json/DF_Join_Small_Rooms.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
{
"version": "1.8.0",
"nickname": "JoinSmall",
"outputs": [
[
{
"access": "None",
"name": "df_obj",
"description": "The input Dragonfly objects with Room2Ds that have had small\nRoom2Ds joined together.",
"type": null,
"default": null
}
]
],
"inputs": [
{
"access": "item",
"name": "_df_obj",
"description": "A Dregonfly Story, Building or Model to have its small Room2Ds\njoined together across the model",
"type": "System.Object",
"default": null
},
{
"access": "item",
"name": "_area_thresh_",
"description": "A number for the Room2D floor area below which it is considered\na small room to be joined into adjacent rooms. (Default: 10.0 square meters).",
"type": "double",
"default": null
}
],
"subcategory": "0 :: Create",
"code": "\ntry: # import the core dragonfly dependencies\n from dragonfly.model import Model\n from dragonfly.building import Building\n from dragonfly.story import Story\nexcept ImportError as e:\n raise ImportError('\\nFailed to import dragonfly:\\n\\t{}'.format(e))\n\ntry: # import the ladybug_{{cad}} dependencies\n from ladybug_{{cad}}.config import tolerance, conversion_to_meters\n from ladybug_{{cad}}.{{plugin}} import all_required_inputs\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 # set the default area threshold\n a_thresh = _area_thresh_ if _area_thresh_ is not None \\\n else 10.0 / conversion_to_meters()\n\n # duplicate the input object and gather all of the stories\n df_obj = _df_obj.duplicate()\n if isinstance(df_obj, Story):\n stories = [df_obj]\n elif isinstance(df_obj, Building):\n stories = df_obj.unique_stories\n elif isinstance(df_obj, Model):\n stories = df_obj.stories\n else:\n msg = 'Expected Dragonfly Story, Building, or Model. Got {}'.format(type(df_obj))\n print(msg)\n raise ValueError(msg)\n\n # merge small rooms together in the story\n for story in stories:\n story.join_small_rooms(a_thresh, tolerance=tolerance)\n",
"category": "Dragonfly",
"name": "DF Join Small Rooms",
"description": "Join small Room2Ds together within Dragonfly Stories.\n_\nThis is particularly useful after operations like automatic core/perimeter\noffsetting, which can create several small Room2Ds from small segments in the\noutline boundary around the Story.\n-"
}
71 changes: 71 additions & 0 deletions dragonfly_grasshopper/src/DF Join Small Rooms.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
# Dragonfly: A Plugin for Environmental Analysis (GPL)
# This file is part of Dragonfly.
#
# Copyright (c) 2024, Ladybug Tools.
# You should have received a copy of the GNU Affero General Public License
# along with Dragonfly; If not, see <http://www.gnu.org/licenses/>.
#
# @license AGPL-3.0-or-later <https://spdx.org/licenses/AGPL-3.0-or-later>

"""
Join small Room2Ds together within Dragonfly Stories.
_
This is particularly useful after operations like automatic core/perimeter
offsetting, which can create several small Room2Ds from small segments in the
outline boundary around the Story.
-

Args:
_df_obj: A Dregonfly Story, Building or Model to have its small Room2Ds
joined together across the model
_area_thresh_: A number for the Room2D floor area below which it is considered
a small room to be joined into adjacent rooms. (Default: 10.0 square meters).

Returns:
report: Reports, errors, warnings, etc.
df_obj: The input Dragonfly objects with Room2Ds that have had small
Room2Ds joined together.
"""

ghenv.Component.Name = 'DF Join Small Rooms'
ghenv.Component.NickName = 'JoinSmall'
ghenv.Component.Message = '1.8.0'
ghenv.Component.Category = 'Dragonfly'
ghenv.Component.SubCategory = '0 :: Create'
ghenv.Component.AdditionalHelpFromDocStrings = '0'

try: # import the core dragonfly dependencies
from dragonfly.model import Model
from dragonfly.building import Building
from dragonfly.story import Story
except ImportError as e:
raise ImportError('\nFailed to import dragonfly:\n\t{}'.format(e))

try: # import the ladybug_rhino dependencies
from ladybug_rhino.config import tolerance, conversion_to_meters
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):
# set the default area threshold
a_thresh = _area_thresh_ if _area_thresh_ is not None \
else 10.0 / conversion_to_meters()

# duplicate the input object and gather all of the stories
df_obj = _df_obj.duplicate()
if isinstance(df_obj, Story):
stories = [df_obj]
elif isinstance(df_obj, Building):
stories = df_obj.unique_stories
elif isinstance(df_obj, Model):
stories = df_obj.stories
else:
msg = 'Expected Dragonfly Story, Building, or Model. Got {}'.format(type(df_obj))
print(msg)
raise ValueError(msg)

# merge small rooms together in the story
for story in stories:
story.join_small_rooms(a_thresh, tolerance=tolerance)
Binary file not shown.