Hi all,

I have created a small script that defined the midpoints based on a input list of points.

I am trying to calculate the distance between all the mid points (d_1,d_2,d_3) and the distance between the first point to the first mid point (m_1), and the distance from the last point to the last mid points (m_2).

Whenever I calculate the distance m2 I get the following error:

**System.ArgumentOutOfRangeException: Index was out of range. Must be non-negative and less than the size of the collection. (Parameter ‘index’)**

** at Rhino.Runtime.Code.Languages.PythonNet.CPythonCode.Execute(RunContext context)**

** at Rhino.Runtime.Code.Code.ExecTry(RunContext context, IPlatformDocument& doc, Object& docState)**

** at Rhino.Runtime.Code.Code.Run(RunContext context)**

Code:

```
<
import Rhino.Geometry as rg
# Input parameter
input_points = your_input_points # Connect your list of points here
# Initialize an empty list to store midpoints
midpoints = []
A = input_points[0]
Z = input_points[-1]
# Compute midpoints between subsequent points
for i in range(len(input_points) - 1):
point1 = input_points[i]
point2 = input_points[i + 1]
midpoint = (point1 + point2) / 2
midpoints.append(midpoint)
# Initialize a list to store distances between midpoints
distances_between_midpoints = []
# Compute distances between consecutive midpoints
for i in range(len(midpoints) - 1):
distance_between_midpoints = rg.Point3d.DistanceTo(midpoints[i], midpoints[i + 1])
distances_between_midpoints.append(distance_between_midpoints)
# Calculate the distance from the first original point to the first midpoint
B = midpoints[0]
distance_to_first_midpoint = A.DistanceTo(B)
# Calculate the distance from the last original point to the last midpoint
C = midpoints[-1]
distance_to_last_midpoint = Z.DistanceTo(C)
# Output the resulting midpoints and distances between midpoints
a = midpoints
b = distances_between_midpoints
c = distance_to_first_midpoint
d = distance_to_last_midpoint>
```

When I do not consider the distance_to_last_midpoint solution, the script works well.

See Code:

```
import Rhino.Geometry as rg
# Input parameter
input_points = your_input_points # Connect your list of points here
# Initialize an empty list to store midpoints
midpoints = []
A = input_points[0]
#Z = input_points[-1]
# Compute midpoints between subsequent points
for i in range(len(input_points) - 1):
point1 = input_points[i]
point2 = input_points[i + 1]
midpoint = (point1 + point2) / 2
midpoints.append(midpoint)
# Initialize a list to store distances between midpoints
distances_between_midpoints = []
# Compute distances between consecutive midpoints
for i in range(len(midpoints) - 1):
distance_between_midpoints = rg.Point3d.DistanceTo(midpoints[i], midpoints[i + 1])
distances_between_midpoints.append(distance_between_midpoints)
# Calculate the distance from the first original point to the first midpoint
B = midpoints[0]
distance_to_first_midpoint = A.DistanceTo(B)
# Calculate the distance from the last original point to the last midpoint
#C = midpoints[-1]
#distance_to_first_midpoint = Z.DistanceTo(C)
# Output the resulting midpoints and distances between midpoints
a = midpoints
b = distances_between_midpoints
c = distance_to_first_midpoint
#d = distance_to_last_midpoint
```

I guess is somthing to do with the [-1] i use to select the last component of the list, but to me it sound quite wired.

Anywone can help?

Thanks in advance