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:

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()
rs.AddRectangle(plane, c[0], c[1])
r = 1
circles = []

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

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


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

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


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[0]-r)
    y = rnd.uniform(r, c[1]-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
        rs.AddCircle(rndPoint, r)

Circles.py (410 Bytes)

1 Like

Thanks so much @pascal , I really appreciate your time and efforts ! :slight_smile: , you saved me

Thanks alot @Mahdiyar , That is a more logic solution I didn’t think about :slight_smile: