Convert <object> to List<Point3d>


I am practicing with C# scripting:

What I want to do is to store some branches (which are list of points) inside a List of List
but I get error saying:

  1. Unable to cast object of type ‘System.Collections.Generic.List1[System.Object]' to type 'System.Collections.Generic.List1[Rhino.Geometry.Point3d]’. (line: 69)

Code below


List seriesPts = new List ();
for (int i = 1; i < x.BranchCount - 1; i++)
seriesPts.Add((List) x.Branch(i));
for (int i = 0; i < seriesPts.Count; i += 2)

  List <Point3d> tempA = (List <Point3d>) (seriesPts[i]);    // line 69 error here
  List <Point3d> tempB = (List <Point3d>) (seriesPts[i + 1]);
  List <object> tempCrv = new List <object>();
  int index = 0;


How can I make it?

Thanks in advance.

Is the tree always points? If so just change the type hint to Point3d instead of Object.

Thanks Michael,

actually this bunch of code comes out from a longer script and the Datatree is built in there.

The tree branches contain always points; anyway, it happens sometimes that I want to convert a type object to another type (i.e. List of Point3d).

How can I perform an Explicit conversion?


You will need to convert to the specific geometries then. See here: How to convert Geometrybase into point3d?

Problem solved.

For those who are interested, I found a compelling explanation here: