Skip to content

Commit

Permalink
fix(serialize): Expose different options for converting HB to DF
Browse files Browse the repository at this point in the history
  • Loading branch information
chriswmackey authored and Chris Mackey committed Mar 25, 2024
1 parent 73738a0 commit 5aad26a
Show file tree
Hide file tree
Showing 16 changed files with 79 additions and 16 deletions.
Binary file modified dragonfly_grasshopper/icon/DF Model From Honeybee.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 dragonfly_grasshopper/icon/DF Visualize All.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 dragonfly_grasshopper/icon/DF Visualize Floors.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 dragonfly_grasshopper/icon/DF Visualize Wireframe.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
11 changes: 9 additions & 2 deletions dragonfly_grasshopper/json/DF_Model_From_Honeybee.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"version": "1.8.0",
"version": "1.8.1",
"nickname": "FromHoneybee",
"outputs": [
[
Expand All @@ -20,6 +20,13 @@
"type": "System.Object",
"default": null
},
{
"access": "item",
"name": "all_3d_to_2d_",
"description": "Boolean to note whether 3D Rooms should be converted\ninto the Room2D format even when this means some loss or\nsimplification of geometry (True). If False (the default), only\nthe Honeybee Rooms that meet the criteria for translation to\nRoom2D without loss of geometry will be converted and the other\n3D Rooms that don't meet this criteria will be stored under the\nDragonfly Building.room_3ds property in their original Honeybee\nformat. (Default: False).",
"type": "bool",
"default": null
},
{
"access": "item",
"name": "incl_shades_",
Expand All @@ -36,7 +43,7 @@
}
],
"subcategory": "2 :: Serialize",
"code": "\ntry: # import the core dragonfly dependencies\n from dragonfly.model import Model\n from dragonfly.building import Building\nexcept ImportError as e:\n raise ImportError('\\nFailed to import dragonfly:\\n\\t{}'.format(e))\n\ntry: # import the core ladybug_{{cad}} dependencies\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) and _load:\n if incl_shades_:\n df_model = Model.from_honeybee(_hb_models[0])\n for h_model in _hb_models[1:]:\n df_model.add_model(Model.from_honeybee(h_model))\n else:\n bldgs = [Building.from_honeybee(h_model) for h_model in _hb_models]\n base = _hb_models[0]\n df_model = Model(\n base.identifier, bldgs, units=base.units, tolerance=base.tolerance,\n angle_tolerance=base.angle_tolerance)\n",
"code": "\ntry: # import the core dragonfly dependencies\n from dragonfly.model import Model\n from dragonfly.building import Building\nexcept ImportError as e:\n raise ImportError('\\nFailed to import dragonfly:\\n\\t{}'.format(e))\n\ntry: # import the core ladybug_{{cad}} dependencies\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) and _load:\n method = 'AllRoom2D' if all_3d_to_2d_ else 'ExtrudedOnly'\n if incl_shades_:\n df_model = Model.from_honeybee(_hb_models[0], conversion_method=method)\n for h_model in _hb_models[1:]:\n df_model.add_model(Model.from_honeybee(h_model, conversion_method=method))\n else:\n bldgs = [Building.from_honeybee(h_model, conversion_method=method)\n for h_model in _hb_models]\n base = _hb_models[0]\n df_model = Model(\n base.identifier, bldgs, units=base.units, tolerance=base.tolerance,\n angle_tolerance=base.angle_tolerance)\n",
"category": "Dragonfly",
"name": "DF Model From Honeybee",
"description": "Create a Dragonfly Model from a Honeybee Model.\n-"
Expand Down
4 changes: 2 additions & 2 deletions dragonfly_grasshopper/json/DF_Visualize_All.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"version": "1.8.0",
"version": "1.8.1",
"nickname": "VizAll",
"outputs": [
[
Expand All @@ -22,7 +22,7 @@
}
],
"subcategory": "1 :: Visualize",
"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\n from dragonfly.room2d import Room2D\n from dragonfly.context import ContextShade\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}}.fromgeometry import from_face3d, from_face3d_to_solid, \\\n from_polyface3d\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\ndef room_2d_geometry(room_2ds):\n \"\"\"Get {{Cad}} geometry from a list of Room2Ds.\"\"\"\n room_geo = []\n for room in room_2ds:\n if room.has_parent and room.parent.roof is not None:\n hb_rm, adj_info = room.to_honeybee()\n room_geo.append(from_polyface3d(hb_rm.geometry))\n else:\n room_geo.append(\n from_face3d_to_solid(room.floor_geometry, room.floor_to_ceiling_height))\n return room_geo\n\n\ndef context_shade_geometry(context_shades):\n \"\"\"Get {{Cad}} geometry from a list of ContextShades.\"\"\"\n return [from_face3d(fc) for shd_geo in context_shades for fc in shd_geo.geometry]\n\n\nif all_required_inputs(ghenv.Component):\n # lists of {{cad}} geometry to be filled with content\n geo = []\n\n # loop through all objects and add them\n for df_obj in _df_objs:\n if isinstance(df_obj, Model):\n rooms = []\n for bldg in df_obj.buildings:\n rooms.extend(bldg.all_room_2ds())\n geo.extend(room_2d_geometry(rooms))\n geo.extend(context_shade_geometry(df_obj.context_shades))\n elif isinstance(df_obj, Building):\n geo.extend(room_2d_geometry(df_obj.all_room_2ds()))\n elif isinstance(df_obj, Story):\n geo.extend(room_2d_geometry(df_obj.room_2ds))\n elif isinstance(df_obj, Room2D):\n geo.extend(room_2d_geometry([df_obj]))\n elif isinstance(df_obj, ContextShade):\n geo.extend(context_shade_geometry([df_obj]))\n",
"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\n from dragonfly.room2d import Room2D\n from dragonfly.context import ContextShade\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}}.fromgeometry import from_face3d, from_face3d_to_solid, \\\n from_polyface3d\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\ndef room_2d_geometry(room_2ds):\n \"\"\"Get {{Cad}} geometry from a list of Room2Ds.\"\"\"\n room_geo = []\n for room in room_2ds:\n if room.has_parent and room.parent.roof is not None:\n hb_rm, adj_info = room.to_honeybee()\n room_geo.append(from_polyface3d(hb_rm.geometry))\n else:\n room_geo.append(\n from_face3d_to_solid(room.floor_geometry, room.floor_to_ceiling_height))\n return room_geo\n\n\ndef room_3d_geometry(room_3ds):\n \"\"\"Get {{Cad}} geometry from a list of 3D Rooms.\"\"\"\n room_geo = []\n for room in room_3ds:\n room_geo.append(from_polyface3d(room.geometry))\n return room_geo\n\n\ndef context_shade_geometry(context_shades):\n \"\"\"Get {{Cad}} geometry from a list of ContextShades.\"\"\"\n return [from_face3d(fc) for shd_geo in context_shades for fc in shd_geo.geometry]\n\n\nif all_required_inputs(ghenv.Component):\n # lists of {{cad}} geometry to be filled with content\n geo = []\n\n # loop through all objects and add them\n for df_obj in _df_objs:\n if isinstance(df_obj, Model):\n rooms = []\n for bldg in df_obj.buildings:\n rooms.extend(bldg.all_room_2ds())\n geo.extend(room_2d_geometry(rooms))\n geo.extend(room_3d_geometry(df_obj.room_3ds))\n geo.extend(context_shade_geometry(df_obj.context_shades))\n elif isinstance(df_obj, Building):\n geo.extend(room_2d_geometry(df_obj.all_room_2ds()))\n geo.extend(room_3d_geometry(df_obj.room_3ds))\n elif isinstance(df_obj, Story):\n geo.extend(room_2d_geometry(df_obj.room_2ds))\n elif isinstance(df_obj, Room2D):\n geo.extend(room_2d_geometry([df_obj]))\n elif isinstance(df_obj, ContextShade):\n geo.extend(context_shade_geometry([df_obj]))\n",
"category": "Dragonfly",
"name": "DF Visualize All",
"description": "Preview any Dragonfly geometry object within the Rhino scene, including all stories\nrepresented by multipliers\n-"
Expand Down
4 changes: 2 additions & 2 deletions dragonfly_grasshopper/json/DF_Visualize_Floors.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"version": "1.8.0",
"version": "1.8.1",
"nickname": "VizFloors",
"outputs": [
[
Expand All @@ -22,7 +22,7 @@
}
],
"subcategory": "1 :: Visualize",
"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\n from dragonfly.room2d import Room2D\n from dragonfly.context import ContextShade\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}}.fromgeometry import from_face3d\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\ndef room_2d_geometry(room_2ds):\n \"\"\"Get {{Cad}} geometry from a list of Room2Ds.\"\"\"\n return [from_face3d(room.floor_geometry) for room in room_2ds]\n\n\ndef context_shade_geometry(context_shades):\n \"\"\"Get {{Cad}} geometry from a list of ContextShades.\"\"\"\n return [from_face3d(fc) for shd_geo in context_shades\n for fc in shd_geo.geometry]\n\n\nif all_required_inputs(ghenv.Component):\n # lists of {{cad}} geometry to be filled with content\n geo = []\n\n # loop through all objects and add them\n for df_obj in _df_objs:\n if isinstance(df_obj, Model):\n rooms = []\n for bldg in df_obj.buildings:\n rooms.extend(bldg.all_room_2ds())\n geo.extend(room_2d_geometry(rooms))\n geo.extend(context_shade_geometry(df_obj.context_shades))\n elif isinstance(df_obj, Building):\n geo.extend(room_2d_geometry(df_obj.all_room_2ds()))\n elif isinstance(df_obj, Story):\n geo.extend(room_2d_geometry(df_obj.room_2ds))\n elif isinstance(df_obj, Room2D):\n geo.extend(room_2d_geometry([df_obj]))\n elif isinstance(df_obj, ContextShade):\n geo.extend(context_shade_geometry([df_obj]))\n",
"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\n from dragonfly.room2d import Room2D\n from dragonfly.context import ContextShade\nexcept ImportError as e:\n raise ImportError('\\nFailed to import dragonfly:\\n\\t{}'.format(e))\n\ntry: # import the core honeybee dependencies\n from honeybee.facetype import Floor\nexcept ImportError as e:\n raise ImportError('\\nFailed to import honeybee:\\n\\t{}'.format(e))\n\ntry: # import the ladybug_{{cad}} dependencies\n from ladybug_{{cad}}.fromgeometry import from_face3d\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\ndef room_2d_geometry(room_2ds):\n \"\"\"Get {{Cad}} geometry from a list of Room2Ds.\"\"\"\n return [from_face3d(room.floor_geometry) for room in room_2ds]\n\n\ndef room_3d_geometry(room_3ds):\n \"\"\"Get {{Cad}} geometry from a list of 3D Rooms.\"\"\"\n room_geo = []\n for room in room_3ds:\n for face in room.faces:\n if isinstance(face.type, Floor):\n room_geo.append(from_face3d(face.geometry))\n return room_geo\n\n\ndef context_shade_geometry(context_shades):\n \"\"\"Get {{Cad}} geometry from a list of ContextShades.\"\"\"\n return [from_face3d(fc) for shd_geo in context_shades\n for fc in shd_geo.geometry]\n\n\nif all_required_inputs(ghenv.Component):\n # lists of {{cad}} geometry to be filled with content\n geo = []\n\n # loop through all objects and add them\n for df_obj in _df_objs:\n if isinstance(df_obj, Model):\n rooms = []\n for bldg in df_obj.buildings:\n rooms.extend(bldg.all_room_2ds())\n geo.extend(room_2d_geometry(rooms))\n geo.extend(room_3d_geometry(df_obj.room_3ds))\n geo.extend(context_shade_geometry(df_obj.context_shades))\n elif isinstance(df_obj, Building):\n geo.extend(room_2d_geometry(df_obj.all_room_2ds()))\n geo.extend(room_3d_geometry(df_obj.room_3ds))\n elif isinstance(df_obj, Story):\n geo.extend(room_2d_geometry(df_obj.room_2ds))\n elif isinstance(df_obj, Room2D):\n geo.extend(room_2d_geometry([df_obj]))\n elif isinstance(df_obj, ContextShade):\n geo.extend(context_shade_geometry([df_obj]))\n",
"category": "Dragonfly",
"name": "DF Visualize Floors",
"description": "Preview any Dragonfly geometry object as floor plates within the Rhino scene,\nincluding all stories represented by multipliers\n-"
Expand Down
4 changes: 2 additions & 2 deletions dragonfly_grasshopper/json/DF_Visualize_Wireframe.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"version": "1.8.0",
"version": "1.8.1",
"nickname": "VizWireF",
"outputs": [
[
Expand All @@ -22,7 +22,7 @@
}
],
"subcategory": "1 :: Visualize",
"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\n from dragonfly.room2d import Room2D\n from dragonfly.context import ContextShade\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}}.fromgeometry import from_face3d_to_wireframe\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\ndef room_2d_geometry(room_2ds):\n \"\"\"Get {{Cad}} geometry curves from a list of Room2Ds.\"\"\"\n return [curve for room in room_2ds for curve in from_face3d_to_wireframe(room.floor_geometry)]\n\ndef context_shade_geometry(context_shades):\n \"\"\"Get {{Cad}} geometry curves from a list of ContextShades.\"\"\"\n \n faces = [face for shd_geo in context_shades\n for face in shd_geo.geometry]\n return [curve for face in faces for curve in from_face3d_to_wireframe(face)]\n\n\nif all_required_inputs(ghenv.Component):\n # lists of {{cad}} geometry to be filled with content\n geo = []\n\n # loop through all objects and add them\n for df_obj in _df_objs:\n if isinstance(df_obj, Model):\n rooms = []\n for bldg in df_obj.buildings:\n rooms.extend(bldg.all_room_2ds())\n geo.extend(room_2d_geometry(rooms))\n geo.extend(context_shade_geometry(df_obj.context_shades))\n elif isinstance(df_obj, Building):\n geo.extend(room_2d_geometry(df_obj.all_room_2ds()))\n elif isinstance(df_obj, Story):\n geo.extend(room_2d_geometry(df_obj.room_2ds))\n elif isinstance(df_obj, Room2D):\n geo.extend(room_2d_geometry([df_obj]))\n elif isinstance(df_obj, ContextShade):\n geo.extend(context_shade_geometry([df_obj]))\n",
"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\n from dragonfly.room2d import Room2D\n from dragonfly.context import ContextShade\nexcept ImportError as e:\n raise ImportError('\\nFailed to import dragonfly:\\n\\t{}'.format(e))\n\ntry: # import the core honeybee dependencies\n from honeybee.facetype import Floor\nexcept ImportError as e:\n raise ImportError('\\nFailed to import honeybee:\\n\\t{}'.format(e))\n\ntry: # import the ladybug_{{cad}} dependencies\n from ladybug_{{cad}}.fromgeometry import from_face3d_to_wireframe\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\ndef room_2d_geometry(room_2ds):\n \"\"\"Get {{Cad}} geometry curves from a list of Room2Ds.\"\"\"\n return [curve for room in room_2ds for curve in\n from_face3d_to_wireframe(room.floor_geometry)]\n\n\ndef room_3d_geometry(room_3ds):\n \"\"\"Get {{Cad}} geometry from a list of 3D Rooms.\"\"\"\n room_geo = []\n for room in room_3ds:\n for face in room.faces:\n if isinstance(face.type, Floor):\n room_geo.extend(from_face3d_to_wireframe(face.geometry))\n return room_geo\n\n\ndef context_shade_geometry(context_shades):\n \"\"\"Get {{Cad}} geometry curves from a list of ContextShades.\"\"\"\n \n faces = [face for shd_geo in context_shades\n for face in shd_geo.geometry]\n return [curve for face in faces for curve in from_face3d_to_wireframe(face)]\n\n\nif all_required_inputs(ghenv.Component):\n # lists of {{cad}} geometry to be filled with content\n geo = []\n\n # loop through all objects and add them\n for df_obj in _df_objs:\n if isinstance(df_obj, Model):\n rooms = []\n for bldg in df_obj.buildings:\n rooms.extend(bldg.all_room_2ds())\n geo.extend(room_2d_geometry(rooms))\n geo.extend(room_3d_geometry(df_obj.room_3ds))\n geo.extend(context_shade_geometry(df_obj.context_shades))\n elif isinstance(df_obj, Building):\n geo.extend(room_2d_geometry(df_obj.all_room_2ds()))\n geo.extend(room_3d_geometry(df_obj.room_3ds))\n elif isinstance(df_obj, Story):\n geo.extend(room_2d_geometry(df_obj.room_2ds))\n elif isinstance(df_obj, Room2D):\n geo.extend(room_2d_geometry([df_obj]))\n elif isinstance(df_obj, ContextShade):\n geo.extend(context_shade_geometry([df_obj]))\n",
"category": "Dragonfly",
"name": "DF Visualize Wireframe",
"description": "Quickly preview any Dragonfly geometry object as a wire frame within the Rhino\nscene, including all stories represented by multipliers\n-"
Expand Down
Loading

0 comments on commit 5aad26a

Please sign in to comment.