Access all points of a list

Hello,

I am trying to add sphere to a grid of points, but I can only seem to add one sphere rather than to the entire grid.
I am sure this is simple.

Thank you, Erik

import rhinoscriptsyntax as rs

    color01 = [255,0,255]
    color02 = [0,255,255]
    color03 = [125,38,205]
    #radius 

    rs.EnableRedraw(False)

    for x in range (0,100,5):
            for y in range(0,100,5):
                pt = rs.AddPoint(x,y,0)
                if x % 4 and y % 9 == 0:
                    rs.ObjectColor(pt, color01)
                elif x % 3 == 0 or y % 6 == 0:
                    rs.ObjectColor(pt, color02)
                else:
                    rs.ObjectColor(pt, color03)



    rs.AddSphere(pt, .25)
    rs.EnableRedraw()

You just need to indent your rs.AddSphere() so it’s at the same level of indentation as pt= currently is - right now it’s outside of your loop…

pt will be a GUID of a point object, as rs.AddPoint() adds a point object to the document. If you want that point, keep the line in, but otherwise you can just add the sphere:

rs.AddSphere([x,y,0], 0.25)

–Mitch

Great thanks Mitch that makes sense.

Now I’m trying to extend it a bit. but it says the guid cannot be converted to a plane. I thought points were planes esp when defined in the x and y axis

import rhinoscriptsyntax as rs
import random as rd
color01 = [255,0,255]
color02 = [0,255,255]
color03 = [125,38,205]
step = 4
rs.EnableRedraw(False)
for x in range (0,100,step):
        for y in range(0,100,step):
            pt = rs.AddPoint(x,y,0)
            cone = rs.AddCone(pt, .5, True)
            if x % 4 and y % 9 == 0:
                sphere = rs.AddSphere(pt, .7)
                rs.ObjectColor(sphere, color01)
            elif x % 3 == 0 or y % 6 == 0:
                rs.ObjectColor(sphere, color02)
                cone = rs.AddCone(pt, .5, True)
            else:
                rs.ObjectColor(sphere, color03)
rs.EnableRedraw()

A GUID is not a point - it is a point OBJECT (one that you can actually see as a point in the document). If you are working with placing objects at points, you do not want to work with point objects added to the document, but rather 3D points that are defined simply by their x,y,z coordinates and are not added as point objects in the document. There’s absolutely no need to use AddPoint() to create points in the Rhino document if you don’t need them, and it will slow things down if you use a lot of them.

import rhinoscriptsyntax as rs
import random as rd

color01 = [255,0,255]
color02 = [0,255,255]
color03 = [125,38,205]


step = 4
rs.EnableRedraw(False)

for x in range (0,100,step):
        for y in range(0,100,step):
            # look at the following line, this creates a rhino/python 3D point
            pt = rs.coerce3dpoint(x,y,0)
            cone = rs.AddCone(pt, .5, True)
            if x % 4 and y % 9 == 0:
                sphere = rs.AddSphere(pt, .7)
                rs.ObjectColor(sphere, color01)
            elif x % 3 == 0 or y % 6 == 0:
                rs.ObjectColor(sphere, color02)
                cone = rs.AddCone(pt, .5, True)
            else:
                rs.ObjectColor(sphere, color03)

Ok that makes sense. Creating the points was definitely slowing down my computation. rs.coerce3dpoint is handy.
Thanks for the help!

Erik

Actually, I am getting an error,
“Message: coerce3dpoint() takes at most 2 arguments (3 given)”

Sorry, my bad, keep forgetting you need to pass the coordinates as a list or tuple:

pt = rs.coerce3dpoint([x,y,0])

Cheers, --Mitch

Great. Thanks. I also found that

pt = (x,y,0)

works as well.

Thanks again.