Civil and construction design tools

Beam Section

How to send command from Excel to draw beam section in AutoCAD ?

Automate AutoCAD with Excel VBA: Drawing a Reinforced Beam Section

Following our previous tutorial on drawing rectangles, this post takes it a step further. Below is a VBA macro that generates a complete Reinforced Concrete Beam section—including the stirrup (tie), top bars, bottom bars, and side bars—directly from your Excel data.

This tool is excellent for structural engineers who need to quickly visualize reinforcement layouts or generate standard details.

The VBA Code

Copy and paste this code into your VBA Editor.

Important: This script uses “Late Binding,” meaning it includes the necessary AutoCAD definitions (like colors and hatch patterns) right in the code. You do not need to mess with “References” in the Tools menu.

option explicit
Const acRed = 1
Const acHatchPatternTypePreDefined = 0
Const acHatchLoopTypeDefault = 0
Sub DrawBeamSection()
Dim AutocadApp As Object
Dim ActDoc As Object
Dim ModelSpace As Object
Dim Rectang As Object
Dim Stirrup As Object
Dim CirObj As Object
Dim FilledCir As Object
Dim Marray(0) As Object
Dim OffsetRect As Variant
Dim SectionCoord(0 To 9) As Double
Dim centerCircle(0 To 2) As Double
Dim BeamWidth As Double, BeamDepth As Double
Dim Cover As Double, StirrupDia As Double
Dim NbrTop As Integer, NbrBot As Integer
Dim DiaTop As Double, DiaBot As Double
Dim DiaMid As Double, MidBarCount As Integer
Dim Spacing As Double
Dim i As Integer
With ActiveSheet
BeamWidth = .Range("F5").Value
BeamDepth = .Range("F6").Value
NbrTop = .Range("F8").Value
DiaTop = .Range("F9").Value
NbrBot = .Range("F10").Value
DiaBot = .Range("F11").Value
MidBarCount = .Range("F12").Value
DiaMid = .Range("F13").Value
Cover = .Range("F14").Value
End With

' Assume a standard stirrup diameter (used for offset calculations)
StirrupDia = 5 ' You can also make this an Excel input

On Error Resume Next
Set AutocadApp = GetObject(, "Autocad.Application")
On Error GoTo 0

If AutocadApp Is Nothing Then
Set AutocadApp = CreateObject("Autocad.Application")
AutocadApp.Visible = True
End If

' Get Active Document and ModelSpace
Set ActDoc = AutocadApp.ActiveDocument
If ActDoc Is Nothing Then Set ActDoc = AutocadApp.Documents.Add
Set ModelSpace = ActDoc.ModelSpace
' Define coordinates (Closing the loop at the end)
SectionCoord(0) = 0: SectionCoord(1) = 0
SectionCoord(2) = BeamWidth: SectionCoord(3) = 0
SectionCoord(4) = BeamWidth: SectionCoord(5) = BeamDepth
SectionCoord(6) = 0: SectionCoord(7) = BeamDepth
SectionCoord(8) = 0: SectionCoord(9) = 0

Set Rectang = ModelSpace.AddLightWeightPolyline(SectionCoord)

' Offset the main rectangle inward by the cover distance
OffsetRect = Rectang.Offset(-Cover)

' The Offset method returns an array of objects. We take the first one.
Set Stirrup = OffsetRect(0)
Stirrup.ConstantWidth = StirrupDia ' Give the stirrup some thickness

' Calculate spacing between bars
' Space = (Width - 2*Cover - 2*Stirrup - OneBarDia) / (Spaces)
' Note: The logic below mimics your original formula logic
Spacing = (BeamWidth - 2 * Cover - DiaBot - (2 * StirrupDia)) / (NbrBot - 1)

For i = 1 To NbrBot
' Calculate X Center
If i = 1 Then
centerCircle(0) = Cover + StirrupDia + (DiaBot / 2)
Else
centerCircle(0) = (Cover + StirrupDia + (DiaBot / 2)) + (Spacing * (i - 1))
End If
' Calculate Y Center
centerCircle(1) = Cover + StirrupDia + (DiaBot / 2)

' Draw and Hatch
Set CirObj = ModelSpace.AddCircle(centerCircle, DiaBot / 2)
CirObj.Color = acRed
Call HatchObject(ModelSpace, CirObj) ' Helper logic called here
Next i

Spacing = (BeamWidth - 2 * Cover - DiaTop - (2 * StirrupDia)) / (NbrTop - 1)

For i = 1 To NbrTop
' Calculate X Center
If i = 1 Then
centerCircle(0) = Cover + StirrupDia + (DiaTop / 2)
Else
centerCircle(0) = (Cover + StirrupDia + (DiaTop / 2)) + (Spacing * (i - 1))
End If
' Calculate Y Center (From top down)
centerCircle(1) = BeamDepth - Cover - StirrupDia - (DiaTop / 2)

' Draw and Hatch
Set CirObj = ModelSpace.AddCircle(centerCircle, DiaTop / 2)
CirObj.Color = acRed
Call HatchObject(ModelSpace, CirObj)
Next i


' Only draws if MidBarCount is set to 2 (one on each side)
If MidBarCount = 2 Then
' Left Side Bar
centerCircle(0) = Cover + StirrupDia + (DiaMid / 2)
centerCircle(1) = BeamDepth / 2
Set CirObj = ModelSpace.AddCircle(centerCircle, DiaMid / 2)
CirObj.Color = acRed
Call HatchObject(ModelSpace, CirObj)

' Right Side Bar
centerCircle(0) = BeamWidth - Cover - StirrupDia - (DiaMid / 2)
centerCircle(1) = BeamDepth / 2
Set CirObj = ModelSpace.AddCircle(centerCircle, DiaMid / 2)
CirObj.Color = acRed
Call HatchObject(ModelSpace, CirObj)
End If

AutocadApp.ZoomExtents
MsgBox "Beam Section Drawn!", vbInformation, "Success"

' Clean up
Set Rectang = Nothing: Set Stirrup = Nothing: Set ActDoc = Nothing: Set AutocadApp = Nothing

End Sub

Sub HatchObject(MSpace As Object, Obj As Object)
Dim Hatch As Object
Dim OuterLoop(0) As Object

Set Hatch = MSpace.AddHatch(0, "Solid", True)
Set OuterLoop(0) = Obj

With Hatch
.AppendOuterLoop OuterLoop
.Evaluate
.Color = 1 ' Red
End With
End Sub

How to setup your Excel Sheet

For the code to run correctly, please set up your Excel sheet with the inputs in the following cells:

Cell Description Example Value
F5 Beam Width 300
F6 Beam Depth 600
F8 Number of Top Bars 3
F9 Top Bar Diameter 16
F10 Number of Bottom Bars 4
F11 Bottom Bar Diameter 20
F12 Number of Side Bars 2
F13 Side Bar Diameter 12
F14 Concrete Cover 40

How to use this program

  1. Fill out the Excel cells as shown in the table above.

  2. Press ALT + F11 to open VBA.

  3. Paste the code into a Module.

  4. Run the macro DrawBeamSection.

  5. Watch AutoCAD draw your beam automatically!

Watch video tutorial HERE ON YouTube

See beam detailing from Excel here