Excel Macro Code

To see what the OpenSTAAD macro is doing, use the developer tools to open the Visual Basic Editor. A macro named OpenSTAADExample has been created to retrieve the maximum sagging moment along the span of the beam as well as the width and depth of the cross-section of the beam. The maximum sagging moment for each load case is extracted, and the governing moment is the largest compression moment of the maximum moments. A second macro named Clear is provided which clears the results from the spreadsheet cells.

OpenSTAADExample

Sub OpenSTAADExample()

    Dim objOpenSTAAD As Object
    Dim stdFile As String
    Dim BaseUnit As Integer
    Dim strLength As String, strForce As String
    
    Dim PrimaryLCs As Integer, LoadCombs As Integer, totalLoads As Integer
    Dim EndForceArray(6) As Double
    Dim lEnd As Long
    
    Dim MemberNo As Long
    Dim Length As Double, Depth As Double, Width As Double
    Dim DMin As Double, dMinPos As Double, DMax As Double, dMaxPos As Double
    Dim Ax As Double, Ay As Double, Az As Double, Ix As Double, Iy As Double, Iz As Double
    
    Dim i As Integer, j As Integer
        
    'Launch OpenSTAAD Object
    Set objOpenSTAAD = GetObject(, "StaadPro.OpenSTAAD")
    
    'Load your STAAD file - make sure you have successfully run the file
    objOpenSTAAD.GetSTAADFile stdFile, "TRUE"
    If stdFile = "" Then
        MsgBox "This macro can only be run with a valid STAAD file loaded.", vbOKOnly
        Set objOpenSTAAD = Nothing
        Exit Sub
    End If

    Cells(2, 2).Value = stdFile
    
    MemberNo = Cells(7, 2).Value
    
    'Check the member exists
    Length = objOpenSTAAD.Geometry.GetBeamLength(MemberNo)
    
    If Length = 0 Then
        MsgBox "Please check the member number is valid.", vbOKOnly
        Set objOpenSTAAD = Nothing
        Exit Sub
    End If
    
    'Find out how many primary load cases and load combinations you have:-
    PrimaryLCs = objOpenSTAAD.Load.GetPrimaryLoadCaseCount()
    Cells(4, 2).Value = PrimaryLCs
    
    LoadCombs = objOpenSTAAD.Load.GetLoadCombinationCaseCount
    Cells(5, 2).Value = LoadCombs
    
    totalLoads = PrimaryLCs + LoadCombs
    
    If totalLoads > 10 Then
        MsgBox ("This macro is designed for up to 10 load cases only")
        Set objOpenSTAAD = Nothing
        Exit Sub
    End If
         
    'What are the units?
    BaseUnit = objOpenSTAAD.GetBaseUnit
    If BaseUnit = 1 Then ' English
        strLength = "Feet"
        strForce = "KIP"
    Else                 ' Metric
        strLength = "Metre"
        strForce = "KN"
        MsgBox ("This macro is designed for up English units. Change STAAD.Pro>Configuration>Base Unit")
        Set objOpenSTAAD = Nothing
        Exit Sub
    End If
    
    Cells(4, 6) = strLength
    Cells(5, 6) = strForce
    
    'Iterate through your load sets to find the results for each load case
    Dim lstLoadPrimaryNums() As Long
    ReDim lstLoadPrimaryNums(PrimaryLCs)
    Dim lstLoadCombinationNums() As Long
    ReDim lstLoadCombinationNums(LoadCombs)
    
    Dim lstLoadNum() As Long
    Dim lstLoadName() As String
    ReDim lstLoadNum(totalLoads)
    ReDim lstLoadName(totalLoads)
    
    objOpenSTAAD.Load.GetPrimaryLoadCaseNumbers lstLoadPrimaryNums
    objOpenSTAAD.Load.GetLoadCombinationCaseNumbers lstLoadCombinationNums
    
    For i = 0 To PrimaryLCs - 1
        lstLoadNum(i) = lstLoadPrimaryNums(i)
        lstLoadName(i) = objOpenSTAAD.Load.GetLoadCaseTitle(lstLoadPrimaryNums(i))
    Next i
        
    For i = 0 To LoadCombs - 1
        lstLoadNum(i + PrimaryLCs) = lstLoadCombinationNums(i)
        lstLoadName(i + PrimaryLCs) = objOpenSTAAD.Load.GetLoadCaseTitle(lstLoadCombinationNums(i))
    Next i
    
    'LoadPrevious = 0
    For i = 0 To totalLoads - 1
        Cells(10, i + 2).Value = lstLoadNum(i)
        Cells(11, i + 2).Value = lstLoadName(i)
        
        'Get forces at start of member
        lEnd = 0
        objOpenSTAAD.Output.GetMemberEndForces MemberNo, lEnd, lstLoadNum(i), EndForceArray
        For j = 0 To 5
            'Print the result values in specified cells
            Cells(j + 13, i + 2).Value = EndForceArray(j)
        Next
        
        'Get forces at end of member
        lEnd = 1
        objOpenSTAAD.Output.GetMemberEndForces MemberNo, lEnd, lstLoadNum(i), EndForceArray
        For j = 0 To 5
            'Print the result values in specified cells
            Cells(j + 20, i + 2).Value = EndForceArray(j)
        Next
         'objOpenSTAAD.GetMinBendingMoment MemberNo, "MZ", LoadNext, MaxSaggingMoment
        objOpenSTAAD.Output.GetMinMaxBendingMoment MemberNo, "MZ", lstLoadNum(i), DMax, dMaxPos, DMin, dMinPos
        Cells(27, i + 2).Value = DMin
    Next
    
    'Write the appropriate dimensions (for the beam) in the correct cells
    Sheets("Concrete").Select
    
    'Get Depth and Width of Concrete Beam
    objOpenSTAAD.Property.GetBeamProperty MemberNo, Width, Depth, Ax, Ay, Az, Ix, Iy, Iz
    'Depth
    Cells(31, 7).Value = Depth
    'Width
    Cells(32, 7).Value = Width
    
    Set objOpenSTAAD = Nothing
    
End Sub

Clear

Sub Clear()
Dim i As Integer
Dim j As Integer

Cells(2, 2) = ""
Cells(4, 2) = 0
Cells(5, 2) = 0

Cells(4, 6) = ""
Cells(5, 6) = ""

For i = 1 To 10
    For j = 1 To 18
        Cells(j + 9, i + 1) = " "
    Next j
Next i

End Sub