AutoCAD Macro to Export Circle Areas to Excel (page)

This VBA macro writes the centre, radius, area and layer of every circle in the drawing to a CSV file for Excel. Useful for counting and sizing trees, poles, manholes or holes.

ExportsX, Y, Radius, Area, Layer
ScopeEvery circle in model space
Outputcircles.csv, next to the drawing

The macro

Sub ExportCircles()
    Dim obj As AcadEntity, c As Variant, f As String
    f = ThisDrawing.Path & "\circles.csv"
    Open f For Output As #1
    Print #1, "X,Y,Radius,Area,Layer"
    For Each obj In ThisDrawing.ModelSpace
        If TypeOf obj Is AcadCircle Then
            c = obj.Center
            Print #1, Trim(Str(c(0))) & "," & Trim(Str(c(1))) & "," & Trim(Str(obj.Radius)) & "," & Trim(Str(obj.Area)) & "," & obj.Layer
        End If
    Next obj
    Close #1
    MsgBox "Saved to " & f, , "XL n CAD"
End Sub

How to run the macro

  1. AutoCAD 2010 and later need the free VBA Enabler from Autodesk for your version. AutoCAD LT doesn't support VBA.
  2. Save the drawing first: the file is written to the drawing's folder.
  3. Type VBAIDE (or press Alt + F11), choose Insert → Module, and paste the code.
  4. Type VBARUN, pick ExportCircles and click Run.
  5. Open circles.csv in Excel.

What changed from the original code

Original code Problem Fixed
Curly quotes “ ” The code won't run Straight quotes
Fixed E: path Fails on most computers Saves next to the drawing
Two text lines per circle (X,Y-…, Area-…) Hard to use in Excel One CSV row per circle, with headers
Opened Notepad at the end Not needed for Excel Message with the file path

Use it in Excel

  • Area is in drawing units squared. If the drawing is in millimetres, divide by 1,000,000 for m².
  • Count circles by layer with a PivotTable: Layer in Rows, Area in Values (Count).
  • Total area of one layer: =SUMIFS(D:D,E:E,"TREES").

Related