I use this script written by Pascal many years to convert a Illustrator Circle to a Rhino Circle use it for creating perforated images in steel created on a CNC punch. The punch call only read pure circle info. Unfortunately cant get the script to work wondering if an update in Rhino has stopped it from working
Any advice on why the script is not working would be great.
I can’t really identify what is wrong with the script. It’s pretty recent, but it doesn’t seem to do the conversion. I have written a similar script in Python which gets the job done. Just download the file and save it in your scripts folder. You can use the command RunPythonScript to run it.
FWIW, you can just use the Rhino command Simplify several times until no more curves are simplified. That would get almost all of them converted to circles.
Thanks Steve - thats great - have used Pascal’s script for years strange that it didnt work same workflow same program I use to generate the pattern. Your python script worked a treat. The Simplify command gets 95% of the circles converted but leaves undone circles behind which again the punch cant handle then finding the needles in the haystack.
Here is another fairly simple script that will convert NURBS curves, that look like circles, to simple circle curves.
import Rhino
import scriptcontext as sc
def MakeEmCircles():
go = Rhino.Input.Custom.GetObject()
go.SetCommandPrompt("Select closed curves to convert to circles")
go.GeometryFilter = Rhino.DocObjects.ObjectType.Curve
go.GeometryAttributeFilter = Rhino.Input.Custom.GeometryAttributeFilter.ClosedCurve
go.GetMultiple(1, 0)
if go.CommandResult() != Rhino.Commands.Result.Success:
return
tolerance = sc.doc.ModelAbsoluteTolerance * 2.0
num_converted = 0
print "Curves selected:", go.ObjectCount
for objref in go.Objects():
curve = objref.Curve()
if not curve: continue
if not isinstance(curve, Rhino.Geometry.NurbsCurve): continue
rc, circle = curve.TryGetCircle(tolerance)
if rc:
new_curve = Rhino.Geometry.ArcCurve(circle)
sc.doc.Objects.Replace(objref, new_curve)
num_converted += 1
sc.doc.Views.Redraw();
print "Curves converted to circles:", num_converted
if __name__=="__main__":
MakeEmCircles()
@Stratosfear, RhinoCommon has a Curve.TryGetEllipse that works similar to the Curve.TryGetCircle method used above. However, Rhino represents ellipses as a rational 2-degree NURBS curve. So it’s not clear what you expect the script to do.