Example - Code/Example - 2 Module 1 - SAP2000
Example - Code/Example - 2 Module 1 - SAP2000
com/help-files/common-api(from-sap-and-
csibridge)/Example_Code/Example_2_(Visual_Basic_2005).htm
Imports SAP2000v19
Module Module1
Sub Main()
AttachToInstance = False
'set the following flag to True to manually specify the path to SAP2000.exe
'this allows for a connection to a version of SAP2000 other than the latest
installation
SpecifyPath = False
'if the above flag is set to True, specify the path to SAP2000 below
Try
System.IO.Directory.CreateDirectory(ModelDirectory)
Catch ex As Exception
End Try
mySapObject = Nothing
ret = -1
If AttachToInstance Then
Try
mySapObject =
DirectCast(System.Runtime.InteropServices.Marshal.GetActiveObject("CSI.SAP2000.API.
SapObject"), cOAPI)
Catch ex As Exception
Return
End Try
Else
Try
Catch ex As Exception
End Try
If SpecifyPath Then
Try
mySapObject = myHelper.CreateObject(ProgramPath)
Catch ex As Exception
Return
End Try
Else
Try
mySapObject =
myHelper.CreateObjectProgID("CSI.SAP2000.API.SapObject")
Catch ex As Exception
Return
End Try
End If
ret = mySapObject.ApplicationStart()
End If
'Get a reference to cSapModel to access all API classes and functions
mySapModel = mySapObject.SapModel
'initialize model
ret = mySapModel.InitializeNewModel()
ret = mySapModel.File.NewBlank()
For i = 0 To 7
ModValue(i) = 1
Next i
ModValue(0) = 1000
ModValue(1) = 0
ModValue(2) = 0
ret = mySapModel.SetPresentUnits(eUnits.kip_ft_F)
For i = 0 To 3
Restraint(i) = True
Next i
For i = 4 To 5
Restraint(i) = False
Next i
For i = 0 To 1
Restraint(i) = True
Next i
For i = 2 To 5
Restraint(i) = False
Next i
PointLoadValue(2) = -10
ReDim PointLoadValue(5)
PointLoadValue(2) = -17.2
PointLoadValue(4) = -54.4
ret = mySapModel.PointObj.SetLoadForce(PointName(1), "3", PointLoadValue)
ret = mySapModel.SetPresentUnits(eUnits.kip_in_F)
'save model
ret = mySapModel.File.Save(ModelPath)
ret = mySapModel.Analyze.RunAnalysis
For i = 0 To 6
ret = mySapModel.Results.Setup.DeselectAllCasesAndCombosForOutput
If i <= 3 Then
ret = mySapModel.Results.JointDispl(PointName(1),
eItemTypeElm.ObjectElm, NumberResults, Obj, Elm, LoadCase, StepType, StepNum, U1,
U2, U3, R1, R2, R3)
SapResult(i) = U3(0)
Else
ret = mySapModel.Results.JointDispl(PointName(0),
eItemTypeElm.ObjectElm, NumberResults, Obj, Elm, LoadCase, StepType, StepNum, U1,
U2, U3, R1, R2, R3)
SapResult(i) = U1(0)
End If
Next i
'close the application
mySapObject.ApplicationExit(False)
mySapModel = Nothing
mySapObject = Nothing
For i = 0 To 6
End If
Next i
IndResult(0) = -0.02639
IndResult(1) = 0.06296
IndResult(2) = 0.06296
IndResult(3) = -0.2963
IndResult(4) = 0.3125
IndResult(5) = 0.11556
IndResult(6) = 0.00651
For i = 0 To 6
End If
Next i
For i As Integer = 0 To 6
End If
Next i
msg = msg & "LC Sap2000 Independent %Diff" & vbCr & vbLf
For i As Integer = 0 To 6
msg = msg & Format(i + 1) & " " & SapResultString(i) & " " &
IndResultString(i) & " " & PercentDiffString(i) & If(i < 6, vbCr & vbLf, "")
Next i
MsgBox(msg)
End Sub
End Module