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.
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()
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?
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…