Example 1 Remarks This example is written for Visual Basic for Applications (VBA). It can be run from a program such as Microsoft Excel. It is based on the SAP2000 verification problem Example 1-001. This example creates the example verification problem from scratch, runs the analysis, extracts results, and compares the results with hand-calculated values. Example Sub VerificationExample1001() 'dimension variables Dim SapObject As SAP2000.SapObject Dim SapModel As cSapModel Dim ret As Long Dim i As Long Dim ModValue() As Double Dim PointLoadValue() As Double Dim Restraint() As Boolean Dim FrameName() As String Dim PointName() As String Dim NumberResults As Long Dim Obj() As String Dim Elm() As String Dim LoadCase() As String Dim StepType() As String Dim StepNum() As Double Dim U1() As Double Dim U2() As Double Dim U3() As Double Dim R1() As Double Dim R2() As Double Dim R3() As Double Dim SapResult() As Double Dim IndResult() As Double Dim PercentDiff() As Double Dim SapResultString() As String Dim IndResultString() As String Dim PercentDiffString() As String Dim msg As String 'create Sap2000 object Set SapObject = New SAP2000.SapObject 'start Sap2000 application SapObject.ApplicationStart Page 1 of 40 Example 1 (VBA) 12-04-2011 file://C:\Documents and Settings\chraud\Local Settings\Temp\~hhCCE8.htm
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Example 1
Remarks
This example is written for Visual Basic for Applications (VBA). It can be run from a program such as Microsoft Excel. It is based on the SAP2000 verification problem Example 1-001.
This example creates the example verification problem from scratch, runs the analysis, extracts results, and compares the results with hand-calculated values.
Example
Sub VerificationExample1001() 'dimension variables Dim SapObject As SAP2000.SapObject Dim SapModel As cSapModel Dim ret As Long Dim i As Long Dim ModValue() As Double Dim PointLoadValue() As Double Dim Restraint() As Boolean Dim FrameName() As String Dim PointName() As String Dim NumberResults As Long Dim Obj() As String Dim Elm() As String Dim LoadCase() As String Dim StepType() As String Dim StepNum() As Double Dim U1() As Double Dim U2() As Double Dim U3() As Double Dim R1() As Double Dim R2() As Double Dim R3() As Double Dim SapResult() As Double Dim IndResult() As Double Dim PercentDiff() As Double Dim SapResultString() As String Dim IndResultString() As String Dim PercentDiffString() As String Dim msg As String 'create Sap2000 object Set SapObject = New SAP2000.SapObject 'start Sap2000 application SapObject.ApplicationStart
Page 1 of 40Example 1 (VBA)
12-04-2011file://C:\Documents and Settings\chraud\Local Settings\Temp\~hhCCE8.htm
'create SapModel object Set SapModel = SapObject.SapModel 'initialize model ret = SapModel.InitializeNewModel 'create new blank model ret = SapModel.File.NewBlank 'define material property ret = SapModel.PropMaterial.SetMaterial("CONC", MATERIAL_CONCRETE) 'assign isotropic mechanical properties to material ret = SapModel.PropMaterial.SetMPIsotropic("CONC", 3600, 0.2, 0.0000055) 'define rectangular frame section property ret = SapModel.PropFrame.SetRectangle("R1", "CONC", 12, 12) 'define frame section property modifiers ReDim ModValue(7) For i = 0 To 7 ModValue(i) = 1 Next i ModValue(0) = 1000 ModValue(1) = 0 ModValue(2) = 0 ret = SapModel.PropFrame.SetModifiers("R1", ModValue) 'switch to k-ft units ret = SapModel.SetPresentUnits(kip_ft_F) 'add frame object by coordinates ReDim FrameName(2) ret = SapModel.FrameObj.AddByCoord(0, 0, 0, 0, 0, 10, FrameName(0), "R1", "1") ret = SapModel.FrameObj.AddByCoord(0, 0, 10, 8, 0, 16, FrameName(1), "R1", "2") ret = SapModel.FrameObj.AddByCoord(-4, 0, 10, 0, 0, 10, FrameName(2), "R1", "3") 'assign point object restraint at base ReDim PointName(1) ReDim Restraint(5) For i = 0 To 3 Restraint(i) = True Next i For i = 4 To 5 Restraint(i) = False Next i ret = SapModel.FrameObj.GetPoints(FrameName(0), PointName(0), PointName(1)) ret = SapModel.PointObj.SetRestraint(PointName(0), Restraint) 'assign point object restraint at top For i = 0 To 1
Page 2 of 40Example 1 (VBA)
12-04-2011file://C:\Documents and Settings\chraud\Local Settings\Temp\~hhCCE8.htm
Restraint(i) = True Next i For i = 2 To 5 Restraint(i) = False Next i ret = SapModel.FrameObj.GetPoints(FrameName(1), PointName(0), PointName(1)) ret = SapModel.PointObj.SetRestraint(PointName(1), Restraint) 'refresh view, update (initialize) zoom ret = SapModel.View.RefreshView(0, False) 'add load patterns ret = SapModel.LoadPatterns.Add("1", LTYPE_OTHER, 1) ret = SapModel.LoadPatterns.Add("2", LTYPE_OTHER) ret = SapModel.LoadPatterns.Add("3", LTYPE_OTHER) ret = SapModel.LoadPatterns.Add("4", LTYPE_OTHER) ret = SapModel.LoadPatterns.Add("5", LTYPE_OTHER) ret = SapModel.LoadPatterns.Add("6", LTYPE_OTHER) ret = SapModel.LoadPatterns.Add("7", LTYPE_OTHER) 'assign loading for load pattern 2 ret = SapModel.FrameObj.GetPoints(FrameName(2), PointName(0), PointName(1)) ReDim PointLoadValue(5) PointLoadValue(2) = -10 ret = SapModel.PointObj.SetLoadForce(PointName(0), "2", PointLoadValue) ret = SapModel.FrameObj.SetLoadDistributed(FrameName(2), "2", 1, 10, 0, 1, 1.8, 1.8) 'assign loading for load pattern 3 ret = SapModel.FrameObj.GetPoints(FrameName(2), PointName(0), PointName(1)) ReDim PointLoadValue(5) PointLoadValue(2) = -17.2 PointLoadValue(4) = -54.4 ret = SapModel.PointObj.SetLoadForce(PointName(1), "3", PointLoadValue) 'assign loading for load pattern 4 ret = SapModel.FrameObj.SetLoadDistributed(FrameName(1), "4", 1, 11, 0, 1, 2, 2) 'assign loading for load pattern 5 ret = SapModel.FrameObj.SetLoadDistributed(FrameName(0), "5", 1, 2, 0, 1, 2, 2, "Local") ret = SapModel.FrameObj.SetLoadDistributed(FrameName(1), "5", 1, 2, 0, 1, -2, -2, "Local") 'assign loading for load pattern 6 ret = SapModel.FrameObj.SetLoadDistributed(FrameName(0), "6", 1, 2, 0, 1, 0.9984, 0.3744, "Local") ret = SapModel.FrameObj.SetLoadDistributed(FrameName(1), "6", 1, 2, 0, 1, -0.3744, 0, "Local") 'assign loading for load pattern 7 ret = SapModel.FrameObj.SetLoadPoint(FrameName(1), "7", 1, 2, 0.5, -15, "Local") 'switch to k-in units ret = SapModel.SetPresentUnits(kip_in_F)
Page 3 of 40Example 1 (VBA)
12-04-2011file://C:\Documents and Settings\chraud\Local Settings\Temp\~hhCCE8.htm
'save model ret = SapModel.File.Save("C:\SapAPI\API_1-001.sdb") 'run model (this will create the analysis model) ret = SapModel.Analyze.RunAnalysis 'initialize for Sap2000 results ReDim SapResult(6) ret = SapModel.FrameObj.GetPoints(FrameName(1), PointName(0), PointName(1)) 'get Sap2000 results for load patterns 1 through 7 For i = 0 To 6 ret = SapModel.Results.Setup.DeselectAllCasesAndCombosForOutput ret = SapModel.Results.Setup.SetCaseSelectedForOutput(Format(i + 1)) If i <= 3 Then ret = SapModel.Results.JointDispl(PointName(1), ObjectElm, NumberResults, Obj, Elm, LoadCase, StepType, StepNum, U1, U2, U3, R1, R2, R3) SapResult(i) = U3(0) Else ret = SapModel.Results.JointDispl(PointName(0), ObjectElm, NumberResults, Obj, Elm, LoadCase, StepType, StepNum, U1, U2, U3, R1, R2, R3) SapResult(i) = U1(0) End If Next i 'close Sap2000 SapObject.ApplicationExit False Set SapModel = Nothing Set SapObject = Nothing 'fill Sap2000 result strings ReDim SapResultString(6) For i = 0 To 6 SapResultString(i) = Format(SapResult(i), "0.00000") If Left(SapResultString(i), 1) <> "-" Then SapResultString(i) = " " & SapResultString(i) End If Next i 'fill independent results (hand calculated) ReDim IndResult(6) ReDim IndResultString(6) 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
Page 4 of 40Example 1 (VBA)
12-04-2011file://C:\Documents and Settings\chraud\Local Settings\Temp\~hhCCE8.htm
IndResultString(i) = Format(IndResult(i), "0.00000") If Left(IndResultString(i), 1) <> "-" Then IndResultString(i) = " " & IndResultString(i) End If Next i 'fill percent difference ReDim PercentDiff(6) ReDim PercentDiffString(6) For i = 0 To 6 PercentDiff(i) = (SapResult(i) / IndResult(i)) - 1 PercentDiffString(i) = Format(PercentDiff(i), "0%") If Left(PercentDiffString(i), 1) <> "-" Then PercentDiffString(i) = " " & PercentDiffString(i) End If Next i 'display message box comparing results msg = "" msg = msg & "LC Sap2000 Independent %Diff" & vbCr & vbLf For i = 0 To 5 msg = msg & Format(i + 1) & " " & SapResultString(i) & " " & IndResultString(i) & " " & PercentDiffString(i) & vbCr & vbLf Next i msg = msg & Format(i + 1) & " " & SapResultString(i) & " " & IndResultString(i) & " " & PercentDiffString(i) MsgBox msg End Sub
Release Notes
Initial release in version 11.03.
Changed nomenclature from Load Cases, Analysis Cases and Response Combinations to Load Patterns, Load Cases and Load Combinations, respectively, in version 12.00.
Example 2 (Visual Basic 2005)
Remarks
This example is written for Visual Basic 2005. It is based on the SAP2000 verification problem Example 1-001.
This example creates the example verification problem from scratch, runs the analysis, extracts results, and compares the results with hand-calculated values.
Example
Page 5 of 40Example 1 (VBA)
12-04-2011file://C:\Documents and Settings\chraud\Local Settings\Temp\~hhCCE8.htm
1. Create a new Visual Basic 2005 project.
2. Add a reference (COM) in the project to the Sap2000.exe.
3. Add a new button to a form in the project.
4. Double click on the new button to bring up the Click procedure for the button and paste in the following code.
'dimension variables Dim SapObject As SAP2000.SapObject Dim SapModel As SAP2000.cSapModel Dim ret As Long Dim i As Long Dim ModValue() As Double Dim PointLoadValue() As Double Dim Restraint() As Boolean Dim FrameName() As String Dim PointName() As String Dim NumberResults As Long Dim Obj() As String Dim Elm() As String Dim LoadCase() As String Dim StepType() As String Dim StepNum() As Double Dim U1() As Double Dim U2() As Double Dim U3() As Double Dim R1() As Double Dim R2() As Double Dim R3() As Double Dim SapResult() As Double Dim IndResult() As Double Dim PercentDiff() As Double Dim SapResultString() As String Dim IndResultString() As String Dim PercentDiffString() As String Dim msg As String 'create Sap2000 object SapObject = New SAP2000.SapObject 'start Sap2000 application SapObject.ApplicationStart() 'create SapModel object SapModel = SapObject.SapModel 'initialize model ret = SapModel.InitializeNewModel
Page 6 of 40Example 1 (VBA)
12-04-2011file://C:\Documents and Settings\chraud\Local Settings\Temp\~hhCCE8.htm
'create new blank model ret = SapModel.File.NewBlank 'define material property ret = SapModel.PropMaterial.SetMaterial("CONC", SAP2000.eMatType.MATERIAL_CONCRETE) 'assign isotropic mechanical properties to material ret = SapModel.PropMaterial.SetMPIsotropic("CONC", 3600, 0.2, 0.0000055) 'define rectangular frame section property ret = SapModel.PropFrame.SetRectangle("R1", "CONC", 12, 12) 'define frame section property modifiers ReDim ModValue(7) For i = 0 To 7 ModValue(i) = 1 Next i ModValue(0) = 1000 ModValue(1) = 0 ModValue(2) = 0 ret = SapModel.PropFrame.SetModifiers("R1", ModValue) 'switch to k-ft units ret = SapModel.SetPresentUnits(SAP2000.eUnits.kip_ft_F) 'add frame object by coordinates ReDim FrameName(2) ret = SapModel.FrameObj.AddByCoord(0, 0, 0, 0, 0, 10, FrameName(0), "R1", "1") ret = SapModel.FrameObj.AddByCoord(0, 0, 10, 8, 0, 16, FrameName(1), "R1", "2") ret = SapModel.FrameObj.AddByCoord(-4, 0, 10, 0, 0, 10, FrameName(2), "R1", "3") 'assign point object restraint at base ReDim PointName(1) ReDim Restraint(5) For i = 0 To 3 Restraint(i) = True Next i For i = 4 To 5 Restraint(i) = False Next i ret = SapModel.FrameObj.GetPoints(FrameName(0), PointName(0), PointName(1)) ret = SapModel.PointObj.SetRestraint(PointName(0), Restraint) 'assign point object restraint at top For i = 0 To 1 Restraint(i) = True Next i For i = 2 To 5 Restraint(i) = False Next i ret = SapModel.FrameObj.GetPoints(FrameName(1), PointName(0), PointName(1))
Page 7 of 40Example 1 (VBA)
12-04-2011file://C:\Documents and Settings\chraud\Local Settings\Temp\~hhCCE8.htm
ret = SapModel.PointObj.SetRestraint(PointName(1), Restraint) 'refresh view, update (initialize) zoom ret = SapModel.View.RefreshView(0, False) 'add load patterns ret = SapModel.LoadPatterns.Add("1", SAP2000.eLoadPatternType.LTYPE_OTHER, 1) ret = SapModel.LoadPatterns.Add("2", SAP2000.eLoadPatternType.LTYPE_OTHER) ret = SapModel.LoadPatterns.Add("3", SAP2000.eLoadPatternType.LTYPE_OTHER) ret = SapModel.LoadPatterns.Add("4", SAP2000.eLoadPatternType.LTYPE_OTHER) ret = SapModel.LoadPatterns.Add("5", SAP2000.eLoadPatternType.LTYPE_OTHER) ret = SapModel.LoadPatterns.Add("6", SAP2000.eLoadPatternType.LTYPE_OTHER) ret = SapModel.LoadPatterns.Add("7", SAP2000.eLoadPatternType.LTYPE_OTHER) 'assign loading for load pattern 2 ret = SapModel.FrameObj.GetPoints(FrameName(2), PointName(0), PointName(1)) ReDim PointLoadValue(5) PointLoadValue(2) = -10 ret = SapModel.PointObj.SetLoadForce(PointName(0), "2", PointLoadValue) ret = SapModel.FrameObj.SetLoadDistributed(FrameName(2), "2", 1, 10, 0, 1, 1.8, 1.8) 'assign loading for load pattern 3 ret = SapModel.FrameObj.GetPoints(FrameName(2), PointName(0), PointName(1)) ReDim PointLoadValue(5) PointLoadValue(2) = -17.2 PointLoadValue(4) = -54.4 ret = SapModel.PointObj.SetLoadForce(PointName(1), "3", PointLoadValue) 'assign loading for load pattern 4 ret = SapModel.FrameObj.SetLoadDistributed(FrameName(1), "4", 1, 11, 0, 1, 2, 2) 'assign loading for load pattern 5 ret = SapModel.FrameObj.SetLoadDistributed(FrameName(0), "5", 1, 2, 0, 1, 2, 2, "Local") ret = SapModel.FrameObj.SetLoadDistributed(FrameName(1), "5", 1, 2, 0, 1, -2, -2, "Local") 'assign loading for load pattern 6 ret = SapModel.FrameObj.SetLoadDistributed(FrameName(0), "6", 1, 2, 0, 1, 0.9984, 0.3744, "Local") ret = SapModel.FrameObj.SetLoadDistributed(FrameName(1), "6", 1, 2, 0, 1, -0.3744, 0, "Local") 'assign loading for load pattern 7 ret = SapModel.FrameObj.SetLoadPoint(FrameName(1), "7", 1, 2, 0.5, -15, "Local") 'switch to k-in units ret = SapModel.SetPresentUnits(SAP2000.eUnits.kip_in_F) 'save model ret = SapModel.File.Save("C:\SapAPI\API_1-001.sdb") 'run model (this will create the analysis model) ret = SapModel.Analyze.RunAnalysis
Page 8 of 40Example 1 (VBA)
12-04-2011file://C:\Documents and Settings\chraud\Local Settings\Temp\~hhCCE8.htm
'initialize for Sap2000 results ReDim SapResult(6) ret = SapModel.FrameObj.GetPoints(FrameName(1), PointName(0), PointName(1)) 'get Sap2000 results for load patterns 1 through 7 ReDim Obj(0) ReDim Elm(0) ReDim LoadCase(0) ReDim StepType(0) ReDim StepNum(0) ReDim U1(0) ReDim U2(0) ReDim U3(0) ReDim R1(0) ReDim R2(0) ReDim R3(0) For i = 0 To 6 ret = SapModel.Results.Setup.DeselectAllCasesAndCombosForOutput ret = SapModel.Results.Setup.SetCaseSelectedForOutput(Format(i + 1)) If i <= 3 Then ret = SapModel.Results.JointDispl(PointName(1), SAP2000.eItemTypeElm.ObjectElm, NumberResults, Obj, Elm, LoadCase, StepType, StepNum, U1, U2, U3, R1, R2, R3) SapResult(i) = U3(0) Else ret = SapModel.Results.JointDispl(PointName(0), SAP2000.eItemTypeElm.ObjectElm, NumberResults, Obj, Elm, LoadCase, StepType, StepNum, U1, U2, U3, R1, R2, R3) SapResult(i) = U1(0) End If Next i 'close Sap2000 SapObject.ApplicationExit(False) SapModel = Nothing SapObject = Nothing 'fill Sap2000 result strings ReDim SapResultString(6) For i = 0 To 6 SapResultString(i) = Format(SapResult(i), "0.00000") If Microsoft.VisualBasic.Left(SapResultString(i), 1) <> "-" Then SapResultString(i) = " " & SapResultString(i) End If Next i 'fill independent results (hand calculated) ReDim IndResult(6) ReDim IndResultString(6) IndResult(0) = -0.02639 IndResult(1) = 0.06296 IndResult(2) = 0.06296
Page 9 of 40Example 1 (VBA)
12-04-2011file://C:\Documents and Settings\chraud\Local Settings\Temp\~hhCCE8.htm
IndResult(3) = -0.2963 IndResult(4) = 0.3125 IndResult(5) = 0.11556 IndResult(6) = 0.00651 For i = 0 To 6 IndResultString(i) = Format(IndResult(i), "0.00000") If Microsoft.VisualBasic.Left(IndResultString(i), 1) <> "-" Then IndResultString(i) = " " & IndResultString(i) End If Next i 'fill percent difference ReDim PercentDiff(6) ReDim PercentDiffString(6) For i = 0 To 6 PercentDiff(i) = (SapResult(i) / IndResult(i)) - 1 PercentDiffString(i) = Format(PercentDiff(i), "0%") If Microsoft.VisualBasic.Left(PercentDiffString(i), 1) <> "-" Then PercentDiffString(i) = " " & PercentDiffString(i) End If Next i 'display message box comparing results msg = "" msg = msg & "LC Sap2000 Independent %Diff" & vbCr & vbLf For i = 0 To 5 msg = msg & Format(i + 1) & " " & SapResultString(i) & " " & IndResultString(i) & " " & PercentDiffString(i) & vbCr & vbLf Next i msg = msg & Format(i + 1) & " " & SapResultString(i) & " " & IndResultString(i) & " " & PercentDiffString(i) MsgBox(msg)
Release Notes
Initial release in version 11.03.
Changed nomenclature from Load Cases, Analysis Cases and Response Combinations to Load Patterns, Load Cases and Load Combinations, respectively, in version 12.00.
Example 3 (Visual C# 2005)
Remarks
This example is written for Visual C# 2005. It is based on the Sap2000 verification problem Example 1-001.
This example creates the example verification problem from scratch, runs the analysis, extracts results, and compares the results with hand calculated values.
Page 10 of 40Example 1 (VBA)
12-04-2011file://C:\Documents and Settings\chraud\Local Settings\Temp\~hhCCE8.htm
Example
1. Create a new Visual C# 2005 project.
2. Add a reference (COM) in the project to the Sap2000.exe.
3. Add a new button to a form in the project.
4. Double click on the new button to bring up the Click procedure for the button and paste in the following code.
Changed nomenclature from Load Cases, Analysis Cases and Response Combinations to Load Patterns, Load Cases and Load Combinations, respectively, in version 12.00.
Example 4 (Intel Visual Fortran v9)
Remarks
This example is written for Intel Visual Fortran v9 with Microsoft Visual Studio Integration. It is based on the SAP2000 verification problem Example 1-001.
This example creates the example verification problem from scratch, runs the analysis, extracts results, and compares the results with hand-calculated values.
Example
1. Create an empty Intel Fortran project.
2. Using the Intel Fortran Module Wizard (under Tools menu), browse for Sap2000.exe, and select all members to generate Sap2000.f90. The generated module contains explicit interfaces to all objects and member functions of the SAP2000 API.
Page 17 of 40Example 1 (VBA)
12-04-2011file://C:\Documents and Settings\chraud\Local Settings\Temp\~hhCCE8.htm
3. Add an empty source file by right clicking on the “Source Files” folder in Solution Explorer and by selecting Add/New Item/Source.
4. Open the newly added file by double clicking on it and paste in the following code:
program APIExample use Sap2000 ! gives access to SAP2000 API calls implicit none !parameters integer(kind=4), parameter :: nDimCON = 1 ! array dimension !local variables integer(kind=4) :: pSapObject ! pointer to a Sap object integer(kind=4) :: pSapModel ! pointer to a model object integer(kind=4) :: pFile ! pointer to a file object integer(kind=4) :: pPropMaterial ! pointer to a material property object integer(kind=4) :: pPropFrame ! pointer to a model object integer(kind=4) :: pFrameObj ! pointer to a frame object integer(kind=4) :: pView ! pointer to a view object integer(kind=4) :: pPointObj ! pointer to a point object integer(kind=4) :: pLoadPatterns ! pointer to a load patterns object integer(kind=4) :: pAnalyze ! pointer to an analyze object integer(kind=4) :: pAnalysisResults ! pointer to a analysis resutls object integer(kind=4) :: pAnalysisResultsSetup ! pointer to a setup object integer(kind=4) :: iStatus ! error code returned from COM subsystem integer(kind=4) :: iRet ! error code returned from SAP2000 API calls integer(kind=4) :: iCol integer(kind=4) :: iUnits integer(kind=4) :: iColor integer(kind=4) :: iWindow integer(kind=4) :: iItemType integer(kind=4) :: iTypleLoadPat integer(kind=4) :: iMyType integer(kind=4) :: iDir integer(kind=4) :: iNumberResults real(kind=8) :: dE real(kind=8) :: dU real(kind=8) :: dA real(kind=8) :: dTemp real(kind=8) :: dT3 real(kind=8) :: dT2 real(kind=8) :: dModValue real(kind=8) :: dXi
Page 18 of 40Example 1 (VBA)
12-04-2011file://C:\Documents and Settings\chraud\Local Settings\Temp\~hhCCE8.htm
12-04-2011file://C:\Documents and Settings\chraud\Local Settings\Temp\~hhCCE8.htm
print *, '-- -------- ----------- -----' do iCol = 1, 7 print 1, iCol, dSapResultsRA1(iCol), dIndResultsRA1(iCol), (dSapResultsRA1(iCol) / dIndResultsRA1(iCol)) - 1. end do 1format ( i3, f10.5, f13.5, f7.2) pause end program APIExample
Release Notes
Initial release in version 11.03.
Changed nomenclature from Load Cases, Analysis Cases and Response Combinations to Load Patterns, Load Cases and Load Combinations, respectively, in version 12.00.
Example 5 (Microsoft Visual C++ 2005)
Remarks
This example is written for Microsoft Visual C++ 2005. It is based on the Sap2000 verification problem Example 1-001.
This example creates the example verification problem from scratch, runs the analysis, extracts results, and compares the results with hand calculated values.
Example
1. Create a Visual C++ Win32 project using the template “Win32 Console Application”.
2. In Win32 Application Wizard, add common header files for ATL under Application Settings tab.
3. Create a folder named “tlb” under the project folder and copy “Sap2000.tlb” from the installation folder to the “tlb” folder.
4. Create a folder named “C:\API” if it does not exist.
5. Open the .cpp file generated by the wizard by double clicking on it and paste in the following code:
#include "stdafx.h" #include <sstream>
Page 27 of 40Example 1 (VBA)
12-04-2011file://C:\Documents and Settings\chraud\Local Settings\Temp\~hhCCE8.htm
This example is written for MATLAB R2008a. It is based on the Sap2000 verification problem Example 1-001.
Page 35 of 40Example 1 (VBA)
12-04-2011file://C:\Documents and Settings\chraud\Local Settings\Temp\~hhCCE8.htm
This example creates the example verification problem from scratch, runs the analysis, extracts results, and compares the results with hand calculated values.
Example
1. Create a folder named “C:\API” if it does not exist.
2. Create a MATLAB .m file using the built-in or any text editor and paste in the following code:
%% clean-up the workspace & command window clear; clc; %% pass data to Sap2000 as one-dimensional arrays feature('COM_SafeArraySingleDim', 1); %% pass non-scalar arrays to Sap2000 API by reference feature('COM_PassSafeArrayByRef', 1); %% create Sap2000 object SapObject = actxserver('sap2000.SapObject'); %% start Sap2000 application SapObject.ApplicationStart; %% create SapModel object SapModel = SapObject.SapModel; %% initialize model ret = SapModel.InitializeNewModel; %% create new blank model ret = SapModel.File.NewBlank; %% define material property MATERIAL_CONCRETE = 2; ret = SapModel.PropMaterial.SetMaterial('CONC', MATERIAL_CONCRETE); %% assign isotropic mechanical properties to material ret = SapModel.PropMaterial.SetMPIsotropic('CONC', 3600, 0.2, 0.0000055); %% define rectangular frame section property ret = SapModel.PropFrame.SetRectangle('R1', 'CONC', 12, 12); %% define frame section property modifiers ModValue = zeros(8,1,'double'); for i = 1 : 8 ModValue(i,1) = 1;
Page 36 of 40Example 1 (VBA)
12-04-2011file://C:\Documents and Settings\chraud\Local Settings\Temp\~hhCCE8.htm
end ModValue(1,1) = 1000; ModValue(2,1) = 0; ModValue(3,1) = 0; ret = SapModel.PropFrame.SetModifiers('R1', ModValue); %% switch to k-ft units kip_ft_F = 4; ret = SapModel.SetPresentUnits(kip_ft_F); %% add frame object by coordinates FrameName1 = ' ';
Restraint = logical(zeros(6,1)); for i = 1 : 4 Restraint(i,1) = true(); end for i = 5 : 6 Restraint(i,1) = false(); end [ret, PointName2] = SapModel.FrameObj.GetPoints(FrameName1, PointName1, PointName2); ret = SapModel.PointObj.SetRestraint(PointName1, Restraint); %% assign point object restraint at top for i = 1 : 2 Restraint(i,1) = true(); end for i = 3 : 6 Restraint(i,1) = false(); end
Page 37 of 40Example 1 (VBA)
12-04-2011file://C:\Documents and Settings\chraud\Local Settings\Temp\~hhCCE8.htm
[ret, PointName1, PointName2] = SapModel.FrameObj.GetPoints(FrameName2, PointName1, PointName2); ret = SapModel.PointObj.SetRestraint(PointName2, Restraint); %% refresh view, update (initialize) zoom ret = SapModel.View.RefreshView(0, false()); %% add load patterns LTYPE_OTHER = 8; ret = SapModel.LoadPatterns.Add('1', LTYPE_OTHER, 1, true()); ret = SapModel.LoadPatterns.Add('2', LTYPE_OTHER, 0, true()); ret = SapModel.LoadPatterns.Add('3', LTYPE_OTHER, 0, true()); ret = SapModel.LoadPatterns.Add('4', LTYPE_OTHER, 0, true()); ret = SapModel.LoadPatterns.Add('5', LTYPE_OTHER, 0, true()); ret = SapModel.LoadPatterns.Add('6', LTYPE_OTHER, 0, true()); ret = SapModel.LoadPatterns.Add('7', LTYPE_OTHER, 0, true()); %% assign loading for load pattern 2 [ret, PointName1, PointName2] = SapModel.FrameObj.GetPoints(FrameName3, PointName1, PointName2); PointLoadValue(6,1) = 0; PointLoadValue(3,1) = -10; ret = SapModel.PointObj.SetLoadForce(PointName1, '2', PointLoadValue); ret = SapModel.FrameObj.SetLoadDistributed(FrameName3, '2', 1, 10, 0, 1, 1.8, 1.8); %% assign loading for load pattern 3 [ret, PointName1, PointName2] = SapModel.FrameObj.GetPoints(FrameName3, PointName1, PointName2); PointLoadValue(6,1) = 0; PointLoadValue(3,1) = -17.2; PointLoadValue(5,1) = -54.4; ret = SapModel.PointObj.SetLoadForce(PointName2, '3', PointLoadValue); %% assign loading for load pattern 4 ret = SapModel.FrameObj.SetLoadDistributed(FrameName2, '4', 1, 11, 0, 1, 2, 2); %% assign loading for load pattern 5 ret = SapModel.FrameObj.SetLoadDistributed(FrameName1, '5', 1, 2, 0, 1, 2, 2, 'Local'); ret = SapModel.FrameObj.SetLoadDistributed(FrameName2, '5', 1, 2, 0, 1, -2, -2, 'Local'); %% assign loading for load pattern 6 ret = SapModel.FrameObj.SetLoadDistributed(FrameName1, '6', 1, 2, 0, 1, 0.9984, 0.3744, 'Local'); ret = SapModel.FrameObj.SetLoadDistributed(FrameName2, '6', 1, 2, 0, 1, -0.3744, 0, 'Local'); %% assign loading for load pattern 7 ret = SapModel.FrameObj.SetLoadPoint(FrameName2, '7', 1, 2, 0.5, -15, 'Local'); %% switch to k-in units kip_in_F = 3; ret = SapModel.SetPresentUnits(kip_in_F);
Page 38 of 40Example 1 (VBA)
12-04-2011file://C:\Documents and Settings\chraud\Local Settings\Temp\~hhCCE8.htm
%% save model ret = SapModel.File.Save('C:\API\API_1-001.sdb'); %% run model (this will create the analysis model) ret = SapModel.Analyze.RunAnalysis(); %% initialize for Sap2000 results SapResult= zeros(7,1,'double'); [ret, PointName1, PointName2] = SapModel.FrameObj.GetPoints(FrameName2, PointName1, PointName2); %% get Sap2000 results for load cases 1 through 7 for i = 1 : 7 NumberResults = 0; Obj = cellstr(' '); Elm = cellstr(' '); ACase = cellstr(' '); StepType = cellstr(' '); StepNum = zeros(1,1,'double'); U1 = zeros(1,1,'double'); U2 = zeros(1,1,'double'); U3 = zeros(1,1,'double'); R1 = zeros(1,1,'double'); R2 = zeros(1,1,'double'); R3 = zeros(1,1,'double'); ObjectElm = 0; ret = SapModel.Results.Setup.DeselectAllCasesAndCombosForOutput; ret = SapModel.Results.Setup.SetCaseSelectedForOutput(int2str(i)); if i <= 4 [ret, NumberResults, Obj, Elm, ACase, StepType, StepNum, U1, U2, U3, R1, R2, R3] = SapModel.Results.JointDispl(PointName2, ObjectElm, NumberResults, Obj, Elm, ACase, StepType, StepNum, U1, U2, U3, R1, R2, R3); SapResult(i) = U3(1); else [ret, NumberResults, Obj, Elm, ACase, StepType, StepNum, U1, U2, U3, R1, R2, R3] = SapModel.Results.JointDispl(PointName1, ObjectElm, NumberResults, Obj, Elm, ACase, StepType, StepNum, U1, U2, U3, R1, R2, R3); SapResult(i) = U1(1); end end %% close Sap2000 ret = SapObject.ApplicationExit(false()); SapModel = 0; SapObject = 0; %% fill independent results IndResult= zeros(7,1,'double'); IndResult(1) = -0.02639;
Page 39 of 40Example 1 (VBA)
12-04-2011file://C:\Documents and Settings\chraud\Local Settings\Temp\~hhCCE8.htm