diff --git a/dragonfly_grasshopper/json/DF_Rejoin_to_Building.json b/dragonfly_grasshopper/json/DF_Rejoin_to_Building.json index 642c637..cab2263 100644 --- a/dragonfly_grasshopper/json/DF_Rejoin_to_Building.json +++ b/dragonfly_grasshopper/json/DF_Rejoin_to_Building.json @@ -1,5 +1,5 @@ { - "version": "1.6.1", + "version": "1.6.2", "nickname": "Rejoin", "outputs": [ [ @@ -22,7 +22,7 @@ } ], "subcategory": "0 :: Create", - "code": "\nfrom collections import OrderedDict\n\ntry: # import the core dragonfly dependencies\n from dragonfly.building import Building\n from dragonfly.story import Story\n from dragonfly.room2d import Room2D\n from dragonfly.colorobj import ColorRoom2D\nexcept ImportError as e:\n raise ImportError('\\nFailed to import dragonfly:\\n\\t{}'.format(e))\n\ntry:\n from ladybug_{{cad}}.{{plugin}} import all_required_inputs, give_warning, \\\n document_counter\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 # duplicate the initial objects\n room2ds = []\n for rm in _room2ds:\n assert isinstance(rm, Room2D), 'Expected Room2D. Got {}.'.format(type(rm))\n room2ds.append(rm.duplicate())\n\n # organize the rooms into a nested dictionary by story/building\n orphaned_rooms = []\n org_dict, bldg_dict = OrderedDict(), OrderedDict()\n for rm in room2ds:\n if rm.has_parent and rm.parent.has_parent:\n story = rm.parent\n bldg = story.parent\n if bldg.identifier not in bldg_dict:\n bldg_dict[bldg.identifier] = bldg\n org_dict[bldg.identifier] = OrderedDict()\n try:\n org_dict[bldg.identifier][story.identifier].append(rm)\n except KeyError:\n org_dict[bldg.identifier][story.identifier] = [rm]\n else:\n orphaned_rooms.append(rm)\n\n # re-generate the Buildings and add the new Room2Ds\n buildings = []\n for bldg in bldg_dict.values():\n new_bldg = bldg.duplicate()\n for story in new_bldg:\n try:\n rm_2ds = org_dict[bldg.identifier][story.identifier]\n story._room_2ds = ()\n story.add_room_2ds(rm_2ds)\n except KeyError: # story missing from the input and we'll use the old ones\n pass\n buildings.append(new_bldg)\n\n # if there were orphaned Room2Ds, add them to their own building\n if len(orphaned_rooms) != 0:\n # give a warning about the orphaned Room2Ds\n display_name = 'Building_{}'.format(document_counter('bldg_count'))\n name = clean_and_id_string(display_name)\n msg = '{} of the input Room2Ds were not a part of an original Dragonfly ' \\\n 'Building.\\nThey have been added to a new Building with the auto-generated ' \\\n 'name \"{}\"\\nBetter practice is to add these Room2Ds to new Stories and ' \\\n 'then a Building.'.format(len(orphaned_rooms), display_name)\n give_warning(ghenv.Component, msg)\n # create the stories and the building\n color_obj = ColorRoom2D(orphaned_rooms, 'floor_height')\n story_groups = [[] for val in values]\n values = color_obj.attributes_unique\n for atr, room in zip(color_obj.attributes, in_rooms):\n atr_i = values.index(atr)\n story_groups[atr_i].append(room)\n stories = [Story('{}_Story{}'.format(name, i), r_group)\n for i, r_group in enumerate(story_groups)]\n o_building = Building(name, stories)\n o_building.display_name = display_name\n buildings.append(o_building)\n", + "code": "\nfrom collections import OrderedDict\n\ntry: # import the core dragonfly dependencies\n from dragonfly.building import Building\n from dragonfly.story import Story\n from dragonfly.room2d import Room2D\n from dragonfly.colorobj import ColorRoom2D\nexcept ImportError as e:\n raise ImportError('\\nFailed to import dragonfly:\\n\\t{}'.format(e))\n\ntry:\n from ladybug_{{cad}}.{{plugin}} import all_required_inputs, give_warning, \\\n document_counter\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 # duplicate the initial objects\n room2ds = []\n for rm in _room2ds:\n assert isinstance(rm, Room2D), 'Expected Room2D. Got {}.'.format(type(rm))\n room2ds.append(rm.duplicate())\n\n # organize the rooms into a nested dictionary by story/building\n orphaned_rooms = []\n org_dict, bldg_dict = OrderedDict(), OrderedDict()\n for rm in room2ds:\n if rm.has_parent and rm.parent.has_parent:\n story = rm.parent\n bldg = story.parent\n if bldg.identifier not in bldg_dict:\n bldg_dict[bldg.identifier] = bldg\n org_dict[bldg.identifier] = OrderedDict()\n try:\n org_dict[bldg.identifier][story.identifier].append(rm)\n except KeyError:\n org_dict[bldg.identifier][story.identifier] = [rm]\n else:\n orphaned_rooms.append(rm)\n\n # re-generate the Buildings and add the new Room2Ds\n buildings = []\n for bldg in bldg_dict.values():\n new_bldg = bldg.duplicate()\n for story in new_bldg:\n try:\n rm_2ds = org_dict[bldg.identifier][story.identifier]\n story._room_2ds = ()\n story.add_room_2ds(rm_2ds)\n except KeyError: # story missing from the input; raise an error\n msg = 'Building \"{}\" could not be reconstructed from the input Room2Ds.\\n' \\\n 'This is likely because the input Room2Ds were created using the \"DF Deconstruct ' \\\n 'All Object\" component\\ninstead of the \"DF Deconstruct Object\" ' \\\n 'component, which preserves the connection of the Room2Ds to the ' \\\n 'original Building.\\nSo you should either relace this component on your ' \\\n 'canvas or, if this is not possible, then you must create the ' \\\n 'Building\\nby joining the Rooms into a new \"DF Story\" and then ' \\\n 'making a new \"DF Building from Stories\".'.format(new_bldg.display_name)\n print(msg)\n raise ValueError(msg)\n buildings.append(new_bldg)\n\n # if there were orphaned Room2Ds, add them to their own building\n if len(orphaned_rooms) != 0:\n # give a warning about the orphaned Room2Ds\n display_name = 'Building_{}'.format(document_counter('bldg_count'))\n name = clean_and_id_string(display_name)\n msg = '{} of the input Room2Ds were not a part of an original Dragonfly ' \\\n 'Building.\\nThey have been added to a new Building with the auto-generated ' \\\n 'name \"{}\"\\nBetter practice is to add these Room2Ds to new Stories and ' \\\n 'then a Building.'.format(len(orphaned_rooms), display_name)\n give_warning(ghenv.Component, msg)\n # create the stories and the building\n color_obj = ColorRoom2D(orphaned_rooms, 'floor_height')\n story_groups = [[] for val in values]\n values = color_obj.attributes_unique\n for atr, room in zip(color_obj.attributes, in_rooms):\n atr_i = values.index(atr)\n story_groups[atr_i].append(room)\n stories = [Story('{}_Story{}'.format(name, i), r_group)\n for i, r_group in enumerate(story_groups)]\n o_building = Building(name, stories)\n o_building.display_name = display_name\n buildings.append(o_building)\n", "category": "Dragonfly", "name": "DF Rejoin to Building", "description": "Rejoin a list of Room2Ds that were originally a part of a Building back to a new\nBuilding with updated Room2Ds.\n_\nIn the event that the input contains Room2Ds that were not a part of an original\nBuilding, this component can still be used but the stories will be regenerated\nbased on the Room2D floor elevations and a warning will be given.\n-" diff --git a/dragonfly_grasshopper/src/DF Rejoin to Building.py b/dragonfly_grasshopper/src/DF Rejoin to Building.py index ed5c595..353ea16 100644 --- a/dragonfly_grasshopper/src/DF Rejoin to Building.py +++ b/dragonfly_grasshopper/src/DF Rejoin to Building.py @@ -28,7 +28,7 @@ ghenv.Component.Name = 'DF Rejoin to Building' ghenv.Component.NickName = 'Rejoin' -ghenv.Component.Message = '1.6.1' +ghenv.Component.Message = '1.6.2' ghenv.Component.Category = 'Dragonfly' ghenv.Component.SubCategory = '0 :: Create' ghenv.Component.AdditionalHelpFromDocStrings = '3' @@ -83,8 +83,17 @@ rm_2ds = org_dict[bldg.identifier][story.identifier] story._room_2ds = () story.add_room_2ds(rm_2ds) - except KeyError: # story missing from the input and we'll use the old ones - pass + except KeyError: # story missing from the input; raise an error + msg = 'Building "{}" could not be reconstructed from the input Room2Ds.\n' \ + 'This is likely because the input Room2Ds were created using the "DF Deconstruct ' \ + 'All Object" component\ninstead of the "DF Deconstruct Object" ' \ + 'component, which preserves the connection of the Room2Ds to the ' \ + 'original Building.\nSo you should either relace this component on your ' \ + 'canvas or, if this is not possible, then you must create the ' \ + 'Building\nby joining the Rooms into a new "DF Story" and then ' \ + 'making a new "DF Building from Stories".'.format(new_bldg.display_name) + print(msg) + raise ValueError(msg) buildings.append(new_bldg) # if there were orphaned Room2Ds, add them to their own building diff --git a/dragonfly_grasshopper/user_objects/DF Rejoin to Building.ghuser b/dragonfly_grasshopper/user_objects/DF Rejoin to Building.ghuser index 70f1731..af95218 100644 Binary files a/dragonfly_grasshopper/user_objects/DF Rejoin to Building.ghuser and b/dragonfly_grasshopper/user_objects/DF Rejoin to Building.ghuser differ diff --git a/samples/des_example.gh b/samples/des_example.gh index a80ed6f..e18b8d2 100644 Binary files a/samples/des_example.gh and b/samples/des_example.gh differ diff --git a/samples/ghe_example.gh b/samples/ghe_example.gh index 974e8bc..e346337 100644 Binary files a/samples/ghe_example.gh and b/samples/ghe_example.gh differ