Fillet all Corners of all Polyline objects

This code will fillet all polyline objects on the active autoCAD document from an excel module. This is useful when you have CNC object that will be cut on a plasma cutter and cant have sharp edges for safety reasons.

Each fillet will have a radius of 0.25 . The radius can be changed by using acadDoc.SetVariable

acadDoc.SetVariable "filletrad", 0.25
before fillet
after fillet

Note: the objects are drawn with PLINETYPE system variable set to 0. This will create LWPOLYLINE or 2D polylines. Also note the polyline objects must be closed.
They can also be drawn with the VBA via AddLightWeightPolyline Method

Start by opening Notepad and pasting the following code. Then save as ‘filletall.lsp’ Put the lsp file in a folder called Support. The folder should be located in the same folder as your worksheet.

(defun c:aeoutline ()
(if (setq i 0 ss (ssget '((0 . "POLYLINE,LWPOLYLINE")(-4 . "&")(70 . 1))))
    (while (< i (sslength ss))
      (setq x (ssname ss i))
      (command "._fillet" "_P" x)
      (setq i (1+ i))

Open vba module in excel and paste the following code.

Sub fillet_all_objects()

    Dim acadApp As Object
    Dim acadDoc As Object
    Dim LispPath As String

    On Error Resume Next               'Check if AutoCAD application is open. If it is not opened create a new instance and make it visible.
    Set acadApp = GetObject(, "AutoCAD.Application")
    If acadApp Is Nothing Then
        Set acadApp = CreateObject("AutoCAD.Application")
        acadApp.Visible = True
    End If
    If acadApp Is Nothing Then         'Check (again) if there is an AutoCAD object.
        MsgBox "Sorry, it was impossible to start AutoCAD!", vbCritical, "AutoCAD Error"
        Exit Sub
    End If
    On Error GoTo 0
    On Error Resume Next
    Set acadDoc = acadApp.ActiveDocument
    If acadDoc Is Nothing Then
        Set acadDoc = acadApp.Documents.Add
    End If
    If acadDoc.ActiveSpace = 0 Then
        acadDoc.ActiveSpace = 1
    End If

    LispPath = ThisWorkbook.Path & "\Support\filletall.lsp"
    LispPath = Replace(LispPath, "\", "/")

    'load the lisp proc to fillet all vertex of polyline
    acadDoc.SetVariable "filletrad", 0.25
    acadDoc.SendCommand "(load " + Chr(34) + LispPath _
        + Chr(34) + ")" + vbCr & "aeoutline" & vbCr & "all " & vbCr

End Sub

Note: I try to avoid using the SendCommand method as much as possible for reasons listed in this article.  I also found that Sendcommand will not return any run-time errors, So if something went wrong, the user will never know.
In this case, I had no other alternative because it was the most efficient/ only way to fillet all objects and all corners.

All finished! Now just run the macro ‘fillet_all_objects’ and see the computer bend to your will.

2 thoughts on “Fillet all Corners of all Polyline objects”

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s