API Examples [PDF]

  • 0 0 0
  • Gefällt Ihnen dieses papier und der download? Sie können Ihre eigene PDF-Datei in wenigen Minuten kostenlos online veröffentlichen! Anmelden
Datei wird geladen, bitte warten...
Zitiervorschau

Example 1 (VBA)

Page 1 of 40

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

file://C:\Documents and Settings\chraud\Local Settings\Temp\~hhCCE8.htm

12-04-2011

Example 1 (VBA)

Page 2 of 40

'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

file://C:\Documents and Settings\chraud\Local Settings\Temp\~hhCCE8.htm

12-04-2011

Example 1 (VBA)

Page 3 of 40

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)

file://C:\Documents and Settings\chraud\Local Settings\Temp\~hhCCE8.htm

12-04-2011

Example 1 (VBA)

Page 4 of 40

'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 ApplicationExit(VARIANT_FALSE); // uninitialize COM CoUninitialize(); return (-1); } }

Release Notes Initial release in version 12.0.1

Example 6 (MATLAB R2008a) Remarks This example is written for MATLAB R2008a. It is based on the Sap2000 verification problem Example 1-001.

file://C:\Documents and Settings\chraud\Local Settings\Temp\~hhCCE8.htm

12-04-2011

Example 1 (VBA)

Page 36 of 40

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;

file://C:\Documents and Settings\chraud\Local Settings\Temp\~hhCCE8.htm

12-04-2011

Example 1 (VBA)

Page 37 of 40

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 = ' '; FrameName2 = ' '; FrameName3 = ' '; [ret, FrameName1] = SapModel.FrameObj.AddByCoord(0, 0, 0, 0, 0, 10, FrameName1, 'R1', '1', Global'); [ret, FrameName2] = SapModel.FrameObj.AddByCoord(0, 0, 10, 8, 0, 16, FrameName2, 'R1', '2', Global'); [ret, FrameName3] = SapModel.FrameObj.AddByCoord(-4, 0, 10, 0, 0, 10, FrameName3, 'R1', '3', Global'); %% assign point object restraint at base PointName1 = ' '; PointName2 = ' ';

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

file://C:\Documents and Settings\chraud\Local Settings\Temp\~hhCCE8.htm

12-04-2011

Example 1 (VBA)

Page 38 of 40

[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);

file://C:\Documents and Settings\chraud\Local Settings\Temp\~hhCCE8.htm

12-04-2011

Example 1 (VBA)

Page 39 of 40

%% 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