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

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…?


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()

This is described at

Ouch, that looks even more painful than the

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



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:


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