 # Unable to convert Guid to curve

Hi All,
Hope you are all safe !. I am trying a very simple code to draw 100 circles inside a rectangle, then I will use 2 loops to delete 1 of every 2 overlapping circles as follows:

for n in range(len(circles)):
for m in range(n+1, len(circles)):
if rs.CurveCurveIntersection(circles[n], circles[m]) != None:
rs.DeleteObject(circles[m])

Where circles is a list containing all created circles, however when I run the script it gives me Message: unable to convert 002b7c29-e30c-4b7b-8d85-02ead6c340a3 into Curve geometry . I am really stuck here and don’t know what to do. I would appreciate any help. You will find the python file attatched.
trial_im_Mai.py (743 Bytes)

Best regards
Karim Youssef

Hi Karim - if you delete the circles as you go, then they no longer exist and the loop is trying to intersect a non-existent curve. You can check for If rs.IsObject(circle) before intersecting, or simply add the circles to a list as you go, and delete them at the end:

``````plane = rs.WorldXYPlane()
r = 1
circles = []

def randompoint():
x = rnd.uniform(a+r, c-r)
y = rnd.uniform(a+r, c-r)
point = (x,y,0)
return point

def drawcircles():
for i in range(0,100):
point = randompoint()
circles.append(circle)
return circles

drawcircles()

delete = []
for n in range(len(circles)):
for m in range(n+1, len(circles)-1):
if rs.CurveCurveIntersection(circles[n], circles[m]) != None:
delete.append(circles[m])
#rs.DeleteObject(circles[m])

rs.DeleteObjects(delete)

``````

Obviously you will want to check for delete being populated at all and so on.

-Pascal

1 Like

Here is another solution, two circles will intersect when `d < r₁+r₂`:

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

c = [50, 25, 0]
r = 1
def randompoint():
x = rnd.uniform(r, c-r)
y = rnd.uniform(r, c-r)
return [x,y,0]

points = []
for i in range(0,100):
rndPoint = randompoint()
for point in points:
if rs.Distance(rndPoint, point) < r*2: break
else:
points.append(rndPoint)
Thanks so much @pascal , I really appreciate your time and efforts ! , you saved me
Thanks alot @Mahdiyar , That is a more logic solution I didn’t think about 