PointCloud.AddRange does not accept list of Point3d

Hi @dale,

i am building a list of 3d points and colors using multiprocessing. To keep those pairs together i add them to a stack of tuples like this:

stack = Sytem.Collections.Concurrent.ConcurrentStack[tuple]()

now i want to add the points with colors to a pointcloud. In Rhino 5 i iterate over each stack item and add the points and colors one by one:

for pt, color in stack.ToArray(): 
    cloud.Add(pt, color)

Unfortunately, this takes very long in V6 compared to V5, so i tried to use the new PointCloud.AddRange method. Since i see no way to use automatic unpacking in the method call i need to create 2 seperate lists, one for points and one for colors. If i then pass the list of points to the method i get this error:

Message: expected PointCloud, got list

Shouldn’t it just accept a list ?
Is there a better way to add the contents from the stack to the pointcloud ?


Not at my machine so working from memory: I think your list needs to be https://developer.rhino3d.com/api/RhinoCommon/html/T_Rhino_Collections_Point3dList.htm

Hi @nathanletwory, thanks below works:

import Rhino
import System
from System.Drawing import Color

cloud = Rhino.Geometry.PointCloud()
stack = System.Collections.Concurrent.ConcurrentStack[tuple]()

p0 = Rhino.Geometry.Point3d(0,0,0)
p1 = Rhino.Geometry.Point3d(0,0,1)
c0 = Color.White
c1 = Color.Red

# threaded
stack.Push( (p0, c0) )
stack.Push( (p1, c1) )

# get points and colors from tuples in stack
p3dlst = Rhino.Collections.Point3dList( [i[0] for i in stack.ToArray()])
colors = System.Collections.Generic.List[Color]( [i[1] for i in stack.ToArray()])

cloud.AddRange(p3dlst, colors)

I’ve expected this to work too:

p3dlst = [item[0] for item in stack.ToArray()]
colors = [item[1] for item in stack.ToArray()]

but it gave me an error:

Multiple targets could match: AddRange(IEnumerable[Point3d], IEnumerable[Color])

unfortunately i cannot add to the cloud inside threading. Is there a way maybe to get rid of the list comprehension and create 2 arrays from the tuples in the stack ?


I don’t know of a better way than creating the Point3dList and List<Color>, but I would do the ToArray() once outside the comprehensions:

arr = stack.ToArray()
p3dlst = Rhino.Collections.Point3dList( [i[0] for i in arr])
colors = System.Collections.Generic.List[Color]( [i[1] for i in arr]

The multiple targets problem I think is because there is an AddRange with Vector3d and an AddRange with Color as the second parameter. Since they look the same when they come from IronPython you get the error. The creation of the List<Color> helps IronPython determine which of the AddRange()s it should use.