Multiple matches error for sc.doc.Objects.AddPoints()

I am getting this:

import Rhino
import scriptcontext as sc
#create point list
ptList=[Rhino.Geometry.Point3d(i,j,k) for i in range(3) for j in range(3) for k in range(3)]
#try to add the list to document
sc.doc.Objects.AddPoints(ptList)

Message: Multiple targets could match: AddPoints(IEnumerable[Point3f]), AddPoints(IEnumerable[Point3d])

Somehow the AddPoints method should know it’s a list of point3d’s, no? Certainly I can use

for pt in ptList : sc.doc.Objects.AddPoint(pt)

but what is sc.doc.Objects.AddPoints() for then? Somehow the overloading of this function is not working…?

–Mitch

1 Like

This one always trips me up. You have to use the special Overloads syntax since python doesn’t support overloaded functions like C#.

import rhinoscriptsyntax as rs
from System.Collections.Generic import IEnumerable
from Rhino.Geometry import Point3d
import scriptcontext

pts = rs.GetPoints()
scriptcontext.doc.Objects.AddPoints.Overloads[IEnumerable[Point3d]](pts)
scriptcontext.doc.Views.Redraw()

This is described at http://blogs.msdn.com/b/haibo_luo/archive/2007/10/11/5413239.aspx

Ouch, that looks even more painful than the

for pt in ptList : sc.doc.Objects.AddPoint(pt)

workaround…

–Mitch

It is going to be faster though, so put up with the pain:)

OK, added to my code snippets for when I “feel the need for speed”… :smile:

Interesting. Is it possibile to overload also for list of lists like
2d_grid =[ [point_0, point_1, point_2, point_3],
[point_4, point_5, point_6, point_7]
[point_8, point_9, point_10, point_11] ]

I could be useful with 2D or 3D grid (point_ is a Point3d obviously… :wink:

I try with

scriptcontext.doc.Objects.AddPoints.Overloads[ IEnumerable[ IEnumerable[Point3d] ] ] (2d_grid)

but I get an error with cast

Probably you shouldn’t create a nested list in the first place, but you can also write this:

scriptcontext.doc.Objects.AddPoints(Rhino.Collections.Point3dList(pts))

Perfect, it works, it needs to iterate with a for loop of course.
I hope that some day also we can use GH_Tree also in scripting, now that I’m pretty confortable with these

Thanks
P