Skip to content

Commit daff8bb

Browse files
committed
ADD check i_assembly has enough beams and if there is an error on a cloud, put None and keep going
1 parent 6b38623 commit daff8bb

File tree

1 file changed

+36
-24
lines changed
  • src/gh/components/DF_main_pc_axes

1 file changed

+36
-24
lines changed

src/gh/components/DF_main_pc_axes/code.py

Lines changed: 36 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,11 @@ def RunScript(self,
1717
i_save: bool,
1818
i_reset: bool):
1919

20+
# ensure assembly has enough beams
21+
if len(i_assembly.beams) < len(i_clouds):
22+
ghenv.Component.AddRuntimeMessage(RML.Warning, "Assembly has fewer beams than input clouds") # noqa: F821
23+
return None, None
24+
2025
planes = []
2126
all_poses_in_time = df_poses.DFPosesAssembly()
2227
if i_reset:
@@ -25,30 +30,37 @@ def RunScript(self,
2530

2631
all_poses_this_time = []
2732
for i, cloud in enumerate(i_clouds):
28-
df_cloud = df_cvt_bindings.cvt_rhcloud_2_dfcloud(cloud)
29-
if df_cloud is None:
30-
return None, None
31-
if not df_cloud.has_normals():
32-
ghenv.Component.AddRuntimeMessage(RML.Error, f"Point cloud {i} has no normals. Please compute the normals.") # noqa: F821
33-
34-
df_points = df_cloud.get_axis_aligned_bounding_box()
35-
df_point = (df_points[0] + df_points[1]) / 2
36-
rh_point = Rhino.Geometry.Point3d(df_point[0], df_point[1], df_point[2])
37-
38-
axes = df_cloud.get_principal_axes(3)
39-
vectors = []
40-
for axe in axes:
41-
vectors.append(Rhino.Geometry.Vector3d(axe[0], axe[1], axe[2]))
42-
43-
new_xDirection, new_yDirection = df_poses.select_vectors(vectors, i_assembly.beams[i].plane.XAxis, i_assembly.beams[i].plane.YAxis)
44-
45-
pose = df_poses.DFPose(
46-
origin = [rh_point.X, rh_point.Y, rh_point.Z],
47-
xDirection = [new_xDirection.X, new_xDirection.Y, new_xDirection.Z],
48-
yDirection = [new_yDirection.X, new_yDirection.Y, new_yDirection.Z])
49-
all_poses_this_time.append(pose)
50-
plane = Rhino.Geometry.Plane(origin = rh_point, xDirection=new_xDirection, yDirection=new_yDirection)
51-
planes.append(plane)
33+
try:
34+
df_cloud = df_cvt_bindings.cvt_rhcloud_2_dfcloud(cloud)
35+
if df_cloud is None:
36+
return None, None
37+
if not df_cloud.has_normals():
38+
ghenv.Component.AddRuntimeMessage(RML.Error, f"Point cloud {i} has no normals. Please compute the normals.") # noqa: F821
39+
40+
df_points = df_cloud.get_axis_aligned_bounding_box()
41+
df_point = (df_points[0] + df_points[1]) / 2
42+
rh_point = Rhino.Geometry.Point3d(df_point[0], df_point[1], df_point[2])
43+
44+
axes = df_cloud.get_principal_axes(3)
45+
vectors = []
46+
for axe in axes:
47+
vectors.append(Rhino.Geometry.Vector3d(axe[0], axe[1], axe[2]))
48+
49+
new_xDirection, new_yDirection = df_poses.select_vectors(vectors, i_assembly.beams[i].plane.XAxis, i_assembly.beams[i].plane.YAxis)
50+
51+
pose = df_poses.DFPose(
52+
origin = [rh_point.X, rh_point.Y, rh_point.Z],
53+
xDirection = [new_xDirection.X, new_xDirection.Y, new_xDirection.Z],
54+
yDirection = [new_yDirection.X, new_yDirection.Y, new_yDirection.Z])
55+
all_poses_this_time.append(pose)
56+
plane = Rhino.Geometry.Plane(origin = rh_point, xDirection=new_xDirection, yDirection=new_yDirection)
57+
planes.append(plane)
58+
except Exception as e:
59+
# Any unexpected error on this cloud, skip it and keep going
60+
ghenv.Component.AddRuntimeMessage(RML.Error, f"Cloud {i}: processing failed ({e}); skipping.") # noqa: F821
61+
planes.append(None)
62+
all_poses_this_time.append(None)
63+
continue
5264

5365
if i_save:
5466
all_poses_in_time.add_step(all_poses_this_time)

0 commit comments

Comments
 (0)