0% found this document useful (0 votes)
227 views

API Code For Truss Optimizer

This subroutine performs structural analysis and design in SAP2000. It opens an existing model file, runs the analysis, performs steel design, and extracts results like member forces, joint reactions, and displacements. Based on these results, it calculates the cost for each frame section and identifies the most cost-effective section for each frame. The best section is then assigned to each frame in the model.

Uploaded by

araz
Copyright
© © All Rights Reserved
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
227 views

API Code For Truss Optimizer

This subroutine performs structural analysis and design in SAP2000. It opens an existing model file, runs the analysis, performs steel design, and extracts results like member forces, joint reactions, and displacements. Based on these results, it calculates the cost for each frame section and identifies the most cost-effective section for each frame. The best section is then assigned to each frame in the model.

Uploaded by

araz
Copyright
© © All Rights Reserved
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 3

Sub api1()

'dimension variables
Dim SapObject As cOAPI
Dim SapModel As cSapModel
Dim FileName As String
Dim ret As Long
Dim numframe As String
Dim numsection As String
Dim NumberItems As Long
Dim FrameName() As String
Dim Ratio() As Double
Dim RatioType() As Long
Dim Location() As Double
Dim ComboName() As String
Dim ErrorSummary() As String
Dim WarningSummary() 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 F1() As Double
Dim F2() As Double
Dim F3() As Double
Dim M1() As Double
Dim M2() As Double
Dim M3() 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
'create Sap2000 object
Set SapObject = CreateObject("CSI.SAP2000.API.SapObject")
'start Sap2000 application
SapObject.ApplicationStart
'create SapModel object
Set SapModel = SapObject.SapModel
'initialize model
ret = SapModel.InitializeNewModel
' numer of frames nad sections
numframe = 3
numsection = 3
'open an existing file
FileName = "C:\Users\araz\Desktop\sap api\beam.sdb"
ret = SapModel.File.OpenFile(FileName)
For nf = 1 To numframe Step 1
Worksheets("Sheet1").Cells(1, nf + 5).Value = "Frame num"
Condition = 0
bsection = 0
bcost = 0
For ns = 1 To numsection Step 1
'unlock model
ret = SapModel.SetModelIsLocked(False)
'set frame section property
ret = SapModel.FrameObj.SetSection(nf, ns)
'save model
ret = SapModel.File.Save("C:\Users\araz\Desktop\sap api\beam
.sdb")
'run model (this will create the analysis model)
ret = SapModel.Analyze.RunAnalysis
'start steel design
ret = SapModel.DesignSteel.StartDesign
'get summary result data
ret = SapModel.DesignSteel.GetSummaryResults(nf, NumberItems
, FrameName, Ratio, RatioType, Location, ComboName, ErrorSummary, WarningSummary
)
R = Ratio(0)
If R <= 1 Then
'clear all case and combo output selections
ret = SapModel.Results.Setup.DeselectAllCasesAndComb
osForOutput
'set case and combo output selections
ret = SapModel.Results.Setup.SetCaseSelectedForOutpu
t("DEAD")
'get joint reactions
Weight = 0
For jno = 1 To 4 Step 1
ret = SapModel.Results.JointReact(jno, Element,
NumberResults, Obj, Elm, LoadCase, StepType, StepNum, F1, F2, F3, M1, M2, M3)
Weight = Weight + F3(0)
Next jno
'get point displacements
dis = 0
ret = SapModel.Results.JointDispl("5", GroupElm
, NumberResults, Obj, Elm, LoadCase, StepType, StepNum, U1, U2, U3, R1, R2, R3)
dis = dis + U3(0)
ret = SapModel.Results.JointDispl("6", GroupElm
, NumberResults, Obj, Elm, LoadCase, StepType, StepNum, U1, U2, U3, R1, R2, R3)
dis = dis + U3(0)
cost = 22500 * Weight + 1182000 * dis
Worksheets("Sheet1").Cells(ns + 1, nf + 5).Valu
e = cost
If Condition = 0 Then
Condition = 1
bsection = ns
bcost = cost
End If
If cost < bcost Then
bsection = ns
bcost = cost
End If
End If
Next ns
'unlock model
ret = SapModel.SetModelIsLocked(False)
'best section assign
ret = SapModel.FrameObj.SetSection(nf, bsection)
Next nf

'close Sap2000
SapObject.ApplicationExit False
Set SapModel = Nothing
Set SapObject = Nothing
End Sub

You might also like