 # Connecting Curves to Random Points Loop

Hey, so I’m very much a beginner when it comes to python scripting, and I’m trying to create a loop for a grid of points where I can created curves that will be randomly generated between these points. I got the grid to work, but I’m currently testing with just lines and I can’t seem to get the lines to connect to these points randomly, here’s the current script:

import rhinoscriptsyntax as rs
import random

xvalues = range(40)
yvalues = range(5,30,1)
points =
for i in xvalues:
for j in yvalues:
points.append(point)

newPointsx =
for i in range(20):
newPointx = random.choice(points)
newPointsx.append(newPointx)
newPointsy =
for j in range(20):
newPointy = random.choice(points)
newPointsy.append(newPointy)

I could be writing this completely wrong, so any help and guidance would be appreciated.

Is this in native Rhino or Grasshopper?

You’re pretty close.
In native Rhino, there is no implied looping so the last line

`rs.AddLine(newPointsx,newPointsy)`

will not work - you cannot feed it two synchronous lists and expect it to work as in GH, it only takes two points. So, you need to explicitly loop through. Also, rs.AddPoint() adds a point object to the Rhino document, what you want is actually a RhinoCommon point3d object which has the point coordinates but doesn’t create a point object in the Rhino document. For this, instead of using rs.AddPoint(), you can use rs.coerce3dpoint(). So it looks more or less like this:

``````
import rhinoscriptsyntax as rs
import random

xvalues = range(40)
yvalues = range(5,30,1)
points = []
for i in xvalues:
for j in yvalues:
point = rs.coerce3dpoint([i,j,0])
points.append(point)

#if you want to add the point objects to the document,uncomment the following

newPointsx = []
for i in range(20):
newPointx = random.choice(points)
newPointsx.append(newPointx)
newPointsy = []
for j in range(20):
newPointy = random.choice(points)
newPointsy.append(newPointy)
#loop through the two lists and add lines
for i in range(len(newPointsx)):
``````

Lastly to format code here place it between 3 backticks like this:

`````````python
paste code here
```
``````

You can also qualify the formatting with the language name as I did above after the first 3 backticks.

Thank you very much, I really appreciate your help. Yes this is native Rhino, not grasshopper. I’m trying to expand onto this by having circles that delete the exterior of the lines, with the inside being filled with the lines originally created. I added the circles, but I’m not sure where to move forward and what command to use when it comes to trimming intersections and such

``````import random

xvalues = range(1,400,5)
yvalues = range(1,200,5)
points = []
for i in xvalues:
for j in yvalues:
point = rs.coerce3dpoint([i,j,0])
points.append(point)

newPointsx = []
for i in range(1200):
newPointx = random.choice(points)
newPointsx.append(newPointx)
newPointsy = []
for j in range(1200):
newPointy = random.choice(points)
newPointsy.append(newPointy)
for i in range(len(newPointsx)):
newCircles = []
for i in range(600):
newCircle = random.choice(points)
newCircles.append(newCircle)
for i in range(len(newCircles)):