Is there a script if you want to convert a curve to arcs and lines at the SAME time.
Normally if you convert a curve you have to choose if you want lines or arcs.
Now I want to convert a curve to arcs but if the radius is bigger than a given number (99999 mm) I like to have lines for that part of the curve, of course within the settings: convert to lines.
This would be a very nice and helpfull tool for cnc cutting machine’s and the cam software.
I know some cam’s have there own sort of filter for this so you get a small cnc file with the accuracy you want. (not everybody owns a cam like that, me neither)
But if there is a script, your drawings will be very small as well.
I search the forum but couldn’t find it.
Maybe I’m missing something but it sounds reasonably straightforward. I would first convert the curve to arcs then go through all the segments and make line of those with a radius greater than your setpoint.
This works as a proof of concept:
import rhinoscriptsyntax as rs
curve=rs.GetObject("Select Curve to Convert",4)
#set the parameters of the convert command
Tol=0.5
AngTol=0.5
#set the arc to line conversion tolerance. An arc with a radius greater than this will be converted to a line
ConvertTolerance=5
cmd="_-Convert " + "Selid " + str(curve) + " _Enter " + "Tolerance " + str(Tol) + " " + "AngleTolerance " + str(AngTol) + " " + "_EnterEnd "
rs.Command(cmd)
ConvertedCurve=rs.LastCreatedObjects()
CurveArcs=rs.ExplodeCurves(ConvertedCurve)
#go through all created arcs, if the radius is > the ConvertTolerance, convert it to a line
for i,Arc in enumerate(CurveArcs):
rad=rs.ArcRadius(Arc)
if rad>ConvertTolerance:
ArcInfo=rs.coercecurve(Arc)
Line=rs.AddLine(ArcInfo.Arc.StartPoint,ArcInfo.Arc.EndPoint)
CurveArcs[i]=Line
rs.DeleteObject(Arc)
#join all segments back into one polycurve
rs.JoinCurves(CurveArcs,True)
rs.DeleteObject(curve)
What does that actually save you in reality? Won’t make your file size any smaller. A line segment is a single line entry in CNC code, so is an arc segment - no matter what the radius…
This is what I sometimes get from customers (see file)
Of course many plates full of them.
With convert to arcs I get it real clean but you will end up with big radius and to big for many cnc controllers.
In my post processor I have a filter but you have to reload (import) the cnc program to see if its done correct, but you can’t check it correctly /easy because of the kerf.
I think a lot of people want to have their drawings correct, meaning as small as possible with no huge arcs before they put it into the cam.
Now I gone find out how to get the script into rhino to test it because my first attempts didn’t work
I think there will be a post.
forgive me my english
With a customer I’ve run into the same issue: somewhere down the line, the arcs that had a too big radius would cause a error/stalling.
@E.O.Stam I believe my customer found a setting when importing that would clean up the arcs with radii that are too large. Maybe it’s an option for your customers as well? If I’m not mistaken I exported splines into a dwg and the customer’s software did the conversion.
The script above is written in python. To access Rhino’s Python editor, type in “_-EditPythonScript” into the command line. Copy and paste that script into the window then click on the green play button at the top.
You can adjust the parameters I entered to suit your needs but it should be noted that the script is only intended as a proof of concept. It has not been tested against any of your typical curves. Having said that though, once you have it working well, you can create a button on Rhino’s UI to run the script rather than from the python editor. Have a look in the Scripting category, you will find lots of examples.
For those finding this topic in the future, @E.O.Stam and I worked out a solution in private.
If anyone is in need of similar functionality and the solution provide by @wattzie is not sufficient, let me know.
Thanks wattzie and Willem this is perfect for cnc cutting my file sizes are never been so small and I have no more errors in my cam software or cnc controller.
After cutting the products looks great as well, and converting is superfast.