Skip to content

Commit

Permalink
fix(extra): Catch the different Exception types Rhino SDK now throws
Browse files Browse the repository at this point in the history
  • Loading branch information
chriswmackey authored and Chris Mackey committed May 31, 2024
1 parent 844523e commit 90182bd
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 5 deletions.
4 changes: 2 additions & 2 deletions ladybug_grasshopper/json/LB_Generate_Point_Grid.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"version": "1.8.0",
"version": "1.8.1",
"nickname": "GenPts",
"outputs": [
[
Expand Down Expand Up @@ -64,7 +64,7 @@
}
],
"subcategory": "4 :: Extra",
"code": "\ntry:\n from ladybug_geometry.geometry3d.plane import Plane\n from ladybug_geometry.geometry3d.face import Face3D\n from ladybug_geometry.geometry3d.mesh import Mesh3D\nexcept ImportError as e:\n raise ImportError('\\nFailed to import ladybug:\\n\\t{}'.format(e))\n\ntry:\n from ladybug_{{cad}}.togeometry import to_gridded_mesh3d, to_mesh3d, \\\n to_face3d, to_vector3d\n from ladybug_{{cad}}.fromgeometry import from_mesh3d, from_point3d, from_vector3d\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 # check the input and generate the mesh.\n _offset_dist_ = _offset_dist_ or 0\n if quad_only_: # use Ladybug's built-in meshing methods\n lb_faces = to_face3d(_geometry)\n try:\n x_axis = to_vector3d(quad_only_)\n lb_faces = [Face3D(f.boundary, Plane(f.normal, f[0], x_axis), f.holes)\n for f in lb_faces]\n except AttributeError:\n pass # no plane connected; juse use default orientation\n lb_meshes = []\n for geo in lb_faces:\n try:\n lb_meshes.append(geo.mesh_grid(_grid_size, offset=_offset_dist_))\n except AssertionError: # tiny geometry not compatible with quad faces\n continue\n if len(lb_meshes) == 0:\n lb_mesh = None\n elif len(lb_meshes) == 1:\n lb_mesh = lb_meshes[0]\n elif len(lb_meshes) > 1:\n lb_mesh = Mesh3D.join_meshes(lb_meshes)\n else: # use {{Cad}}'s default meshing\n try: # assume it's a {{Cad}} Brep\n lb_mesh = to_gridded_mesh3d(_geometry, _grid_size, _offset_dist_)\n except TypeError: # assume it's a {{Cad}} Mesh\n try:\n lb_mesh = to_mesh3d(_geometry)\n except TypeError: # unidientified geometry type\n raise TypeError(\n '_geometry must be a Brep or a Mesh. Got {}.'.format(type(_geometry)))\n\n # generate the test points, vectors, and areas.\n if lb_mesh is not None:\n points = [from_point3d(pt) for pt in lb_mesh.face_centroids]\n vectors = [from_vector3d(vec) for vec in lb_mesh.face_normals]\n face_areas = lb_mesh.face_areas\n mesh = [from_mesh3d(lb_mesh)]\n else:\n mesh = []",
"code": "\ntry:\n from ladybug_geometry.geometry3d.plane import Plane\n from ladybug_geometry.geometry3d.face import Face3D\n from ladybug_geometry.geometry3d.mesh import Mesh3D\nexcept ImportError as e:\n raise ImportError('\\nFailed to import ladybug:\\n\\t{}'.format(e))\n\ntry:\n from ladybug_{{cad}}.togeometry import to_gridded_mesh3d, to_mesh3d, \\\n to_face3d, to_vector3d\n from ladybug_{{cad}}.fromgeometry import from_mesh3d, from_point3d, from_vector3d\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 # check the input and generate the mesh.\n _offset_dist_ = _offset_dist_ or 0\n if quad_only_: # use Ladybug's built-in meshing methods\n lb_faces = to_face3d(_geometry)\n try:\n x_axis = to_vector3d(quad_only_)\n lb_faces = [Face3D(f.boundary, Plane(f.normal, f[0], x_axis), f.holes)\n for f in lb_faces]\n except AttributeError:\n pass # no plane connected; juse use default orientation\n lb_meshes = []\n for geo in lb_faces:\n try:\n lb_meshes.append(geo.mesh_grid(_grid_size, offset=_offset_dist_))\n except AssertionError: # tiny geometry not compatible with quad faces\n continue\n if len(lb_meshes) == 0:\n lb_mesh = None\n elif len(lb_meshes) == 1:\n lb_mesh = lb_meshes[0]\n elif len(lb_meshes) > 1:\n lb_mesh = Mesh3D.join_meshes(lb_meshes)\n else: # use {{Cad}}'s default meshing\n try: # assume it's a {{Cad}} Brep\n lb_mesh = to_gridded_mesh3d(_geometry, _grid_size, _offset_dist_)\n except Exception: # assume it's a {{Cad}} Mesh\n try:\n lb_mesh = to_mesh3d(_geometry)\n except Exception: # unidientified geometry type\n raise TypeError(\n '_geometry must be a Brep or a Mesh. Got {}.'.format(type(_geometry)))\n\n # generate the test points, vectors, and areas.\n if lb_mesh is not None:\n points = [from_point3d(pt) for pt in lb_mesh.face_centroids]\n vectors = [from_vector3d(vec) for vec in lb_mesh.face_normals]\n face_areas = lb_mesh.face_areas\n mesh = [from_mesh3d(lb_mesh)]\n else:\n mesh = []",
"category": "Ladybug",
"name": "LB Generate Point Grid",
"description": "Genrate a mesh with corresponding test points from a Rhino Brep (or Mesh).\n_\nThe resulting mesh will be in a format that the \"LB Spatial Heatmap\" component\nwill accept.\n-"
Expand Down
6 changes: 3 additions & 3 deletions ladybug_grasshopper/src/LB Generate Point Grid.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@

ghenv.Component.Name = "LB Generate Point Grid"
ghenv.Component.NickName = 'GenPts'
ghenv.Component.Message = '1.8.0'
ghenv.Component.Message = '1.8.1'
ghenv.Component.Category = 'Ladybug'
ghenv.Component.SubCategory = '4 :: Extra'
ghenv.Component.AdditionalHelpFromDocStrings = '1'
Expand Down Expand Up @@ -86,10 +86,10 @@
else: # use Rhino's default meshing
try: # assume it's a Rhino Brep
lb_mesh = to_gridded_mesh3d(_geometry, _grid_size, _offset_dist_)
except TypeError: # assume it's a Rhino Mesh
except Exception: # assume it's a Rhino Mesh
try:
lb_mesh = to_mesh3d(_geometry)
except TypeError: # unidientified geometry type
except Exception: # unidientified geometry type
raise TypeError(
'_geometry must be a Brep or a Mesh. Got {}.'.format(type(_geometry)))

Expand Down
Binary file modified ladybug_grasshopper/user_objects/LB Generate Point Grid.ghuser
Binary file not shown.

0 comments on commit 90182bd

Please sign in to comment.