Central point or sphere based on circles set - automate

Hello,

is there any way to automate the process of spheres creation? I have a set of closed curves (circles). I would like to make spheres of all the selected circles (>100). Obviously it makes no sense to click each circle and create spheres.

I know how to automate it with AddSphere command in Rhino Python but I need central points of each circle for that operation. The suggestion how to create central points of each circle in the set would be also valuable.

Thanks in advance!

Kuba

Something like this should work…

import rhinoscriptsyntax as rs

#circles
def circ_filt(rhino_object, geometry, component_index):
    return geometry.IsCircle()

def AddSpheresToCircles():
    msg="Select circles to add spheres"
    crvs=rs.GetObjects(msg,4,preselect=True,custom_filter=circ_filt)
    if not crvs: return
    rs.EnableRedraw(False)
    for crv in crvs:
        ctr=rs.CircleCenterPoint(crv)
        rad=rs.CircleRadius(crv)
        rs.AddSphere(ctr,rad)
        #rs.AddPoint(ctr)  #optional to add a point object in center
AddSpheresToCircles()

–Mitch

Thanks for your quick answer. For some reason I cannot select any circles after running the script even after changing the filter in getobjects to 0 (all) and gettiing the defined message “Select circles to add spheres”. Any ideas why?

Okay, it looks like (for some reason), the curves that I have are not really circles… Any ideas how to fix this?

They are curves made with function TextObject (Braille font used).

Yep. If they will not simplify to circles with the native SimplifyCrv command, you can run the following script on them. Depending on how far out from a real circle they are, you will need to set a tolerance for the conversion at the command line. If you set the tolerance to 0, it will turn ANY closed planar curve into a circle…

SimplifyRecalcitrantCircles2.py (3.6 KB)

2 Likes

That is awesome! It works now. Looks like these “circles” were in reality polygons with like 20 sides…