PointCloud.RemoveRange not removing anything

So I wrote this code where the user selects a point cloud, then points they wish to remove.
However, while I am able to get (what I assume are) the correct indices of these points, the RemoveRange doesn’t seem to remove anything. The .Count() on the cloud remains the same and the point cloud in Rhino itself remains unchanged.

            var rc = RhinoGet.GetOneObject("Select point cloud", false, ObjectType.PointSet, out var cloud_obj_ref);
            if (rc != Result.Success)
            {
                return rc;
            }

            ObjRef[] point_obj_refs;
            rc = Rhino.Input.RhinoGet.GetMultipleObjects("Select points", false, ObjectType.Point, out point_obj_refs);
            if (rc != Result.Success)
            {
                return rc;
            }

            List<int> indices = new List<int>();

            foreach (var o_ref in point_obj_refs)
            {
                var point_index = o_ref.GeometryComponentIndex.Index;
                indices.Add(point_index);
            }

            cloud_obj_ref.PointCloud().RemoveRange(indices);

            doc.Views.Redraw();

            RhinoApp.WriteLine("Deleted " + indices.Count + " points.");
            RhinoApp.WriteLine("Point Cloud now has " + cloud_obj_ref.PointCloud().Count + " points.");

            return Result.Success;

Hi @niekd,

Try this:

protected override Result RunCommand(RhinoDoc doc, RunMode mode)
{
  var rc = RhinoGet.GetOneObject("Select point cloud", false, ObjectType.PointSet, out var cloud_obj_ref);
  if (rc != Result.Success)
    return rc;

  rc = Rhino.Input.RhinoGet.GetMultipleObjects("Select points", false, ObjectType.Point, out var point_obj_refs);
  if (rc != Result.Success)
    return rc;

  var indices = new List<int>();
  foreach (var o_ref in point_obj_refs)
  {
    var point_index = o_ref.GeometryComponentIndex.Index;
    indices.Add(point_index);
  }

  var point_cloud = (PointCloud) cloud_obj_ref.PointCloud().Duplicate();
  point_cloud.RemoveRange(indices);

  RhinoApp.WriteLine("Deleted " + indices.Count + " points.");
  RhinoApp.WriteLine("Point Cloud now has " + cloud_obj_ref.PointCloud().Count + " points.");

  doc.Objects.Replace(cloud_obj_ref, point_cloud);
  doc.Views.Redraw();

  return Result.Success;
}

– Dale