提供API(接口)供二次开发的软件就是好软件。像ansys,AutoCAD,office等,用vba或LISP或APDL等,做一些自动化的开发。
sap2000也提供了API。
可以在excel vba里直接写代码,先在excel里输入参数,点击运行,自动在sap2000里建模和加荷载,甚至运行和提取结果都可以。
只不过,任何自动化都需要人为去慢慢做,然后才享受。
比如,建立一个方井或圆井模型,进行内水压力和外土水压力、底部扬压力荷载和约束的添加可以用API。

Sub InitializeNewModel()
   'dimension variables
      Dim SapObject As Sap2000v15.SapObject
      Dim SapModel As cSapModel
      Dim ret As Long

        '半径
        Dim R0 As Double

        '高
        Dim H0 As Long

        '飘板宽
        Dim B1 As Double

        '底板厚
        Dim H1 As Double

        '侧墙底部厚
        Dim B2 As Double
        '侧墙顶部厚
        Dim B3 As Double
        '填土高
        Dim H2 As Double
        '温差
        Dim T0 As Double
        '砼强度等级
        Dim CONC As String
        '钢筋型号
        Dim STEEL As String

        '地基刚度
        Dim K0 As Double
        '侧土压力系数
        Dim K1 As Double

'模型坐标
'      Dim x() As Double
'      Dim y() As Double
'      Dim z() As Double
      Dim r As Double, Theta1 As Double, Theta2 As Double, z As Double
      Dim Name As String
      Dim MyName As String
      Dim UserName As String
      Dim PointName() As String
      Dim FrameName() As String
      Dim Point() As String
      Dim Vec() As Double

      Dim MyLoadType() As String
      Dim MyLoadName() As String
      Dim MySF() As Double

      Dim k() As Double '弹簧刚度
      Dim Thickness() As Double
      Dim NumberAreas As Long
      Dim AreaName() As String
      Dim VALUE() As Boolean
      Dim ObjectName() As String
      Dim ObjectType() As Long
      Dim NumberObjects As Long
'0.初始化
    'create Sap2000 object
      Set SapObject = New Sap2000v15.SapObject
    'start Sap2000 application
       SapObject.ApplicationStart
    'create SapModel object
      Set SapModel = SapObject.SapModel
    'initialize model
      ret = SapModel.InitializeNewModel(kip_ft_F)
    'initialize new model
      SapModel.InitializeNewModel (kN_m_C)
    'create model from template
      ret = SapModel.File.NewBlank
'00.获取excel中基本数据
        R0 = Sheets("圆筒").Range("E" & 2).VALUE
        H0 = Sheets("圆筒").Range("E" & 3).VALUE
        B1 = Sheets("圆筒").Range("E" & 4).VALUE
        H1 = Sheets("圆筒").Range("E" & 5).VALUE
        B2 = Sheets("圆筒").Range("E" & 6).VALUE
        B3 = Sheets("圆筒").Range("E" & 7).VALUE
        H2 = Sheets("圆筒").Range("E" & 8).VALUE
        T0 = Sheets("圆筒").Range("E" & 9).VALUE
        K0 = Sheets("圆筒").Range("E" & 10).VALUE
        CONC = Sheets("圆筒").Range("E" & 11).VALUE
        STEEL = Sheets("圆筒").Range("E" & 12).VALUE
        K1 = Sheets("圆筒").Range("E" & 24).VALUE

 '1.定义材料:砼C30,C25、钢筋HRB400,335、钢板Q345,235
    'delete material
   ret = SapModel.PropMaterial.Delete("4000Psi")
   ret = SapModel.PropMaterial.AddQuick(Name, MATERIAL_CONCRETE, , MATERIAL_CONCRETE_SUBTYPE_CHINESE_C30_NORMALWEIGHT)
   ret = SapModel.PropMaterial.AddQuick(Name, MATERIAL_CONCRETE, , MATERIAL_CONCRETE_SUBTYPE_CHINESE_C40_NORMALWEIGHT)
   ret = SapModel.PropMaterial.AddQuick(Name, MATERIAL_REBAR, , , , , MATERIAL_REBAR_SUBTYPE_CHINESE_HRB400)
   ret = SapModel.PropMaterial.AddQuick(Name, MATERIAL_REBAR, , , , , MATERIAL_REBAR_SUBTYPE_CHINESE_HRB335)
   ret = SapModel.PropMaterial.AddQuick(Name, MATERIAL_STEEL, MATERIAL_STEEL_SUBTYPE_CHINESE_Q235)
   ret = SapModel.PropMaterial.AddQuick(Name, MATERIAL_STEEL, MATERIAL_STEEL_SUBTYPE_CHINESE_Q345)
  'initialize new material property
      'ret = SapModel.PropMaterial.SetMaterial("Steel", MATERIAL_STEEL)
  '定义材料参数
    'assign material property weight per unit volume
      'ret = SapModel.PropMaterial.SetWeightAndMass("Steel", 1, 0.00029)
         'assign isotropic mechanical properties
      'ret = SapModel.PropMaterial.SetMPIsotropic("Steel", 29500, 0.25, 0.000006)
   'assign other properties
      'ret = SapModel.PropMaterial.SetOConcrete_1("Concrete", 5, False, 0, 1, 2, 0.0022, 0.0052, -0.1)

'2.定义梁截面和板截面,同时确定材料
   'set new area property有3中面单元:板壳单元,包括薄壳、厚壳,薄板,厚板ShellType有6种;平面单元;轴对称实体单元
   '对于壳的厚度h 与其宽度L 之比( 即厚宽比) h/L< l/ lO 的壳称为薄壳,壳的厚宽比在1 / 10<h/L <1/5 之间的壳,称为中厚壳
      ret = SapModel.PropArea.SetShell_1("DIBAN", 1, True, "C30", 0, H1, H1)
      ret = SapModel.PropArea.SetShell_1("CEQIANG", 1, True, "C30", 0, B2, B2)

 'set area property design parameters
      ret = SapModel.PropArea.SetShellDesign("DIBAN", "HRB400", 0, 0, 0, 0, 0) '不知道为何后面钢筋保护层厚度还要赋值
      ret = SapModel.PropArea.SetShellDesign("CEQIANG", "HRB400", 0, 0, 0, 0, 0)

'3.定义节点样式名称
'add joint pattern
      ret = SapModel.PatternDef.SetPattern("DIXIASHUI")
      ret = SapModel.PatternDef.SetPattern("TIANTU")
      ret = SapModel.PatternDef.SetPattern("NEISHUI")
'4.定义荷载模式:活、恒、风、地震……自重    水重    静水压力    扬压力  土压力  淤沙压力    风压力  浪压力  冰压力  土的冻胀力  地震荷载    其他

'   '地震荷载add new load pattern
'      ret = SapModel.LoadPatterns.Add("EQX", LTYPE_QUAKE)
'
'   'assign Chinese 2010 parameters
'      ret = SapModel.LoadPatterns.AutoSeismic.SetChinese2010("EQX", 1, 0.05, 2, 0, False, 0, 0, 0.16, 4, 0.06, 0.4, 1, 1)
'
'   '风荷载define diaphragm constraints
'      ret = SapModel.ConstraintDef.SetDiaphragm("Diaph1", z)
'      ret = SapModel.ConstraintDef.SetDiaphragm("Diaph2", z)
'
'   'assign points to diaphragm
'      ret = SapModel.SelectObj.ClearSelection
'      ret = SapModel.SelectObj.PlaneXY("2")
'      ret = SapModel.PointObj.SetConstraint("", "Diaph1", SelectedObjects)
'      ret = SapModel.SelectObj.ClearSelection
'      ret = SapModel.SelectObj.PlaneXY("3")
'      ret = SapModel.PointObj.SetConstraint("", "Diaph2", SelectedObjects)
'      ret = SapModel.SelectObj.ClearSelection
'   'add new load pattern
'      ret = SapModel.LoadPatterns.Add("WIND", LTYPE_WIND)
'   'assign Chinese2010 parameters
'      ret = SapModel.LoadPatterns.AutoWind.SetChinese2010("WIND", 1, 0, 1200, 0.5, False, 1, False, 0, 0, 0.48, 3, 1, 1, 0.6, 0.04)

   'add new load pattern
      ret = SapModel.LoadPatterns.Add("CETUYALI", LTYPE_LIVE)
      ret = SapModel.LoadPatterns.Add("DIXIASHUIYALI", LTYPE_LIVE)
      ret = SapModel.LoadPatterns.Add("DIXIASHUIFULI", LTYPE_LIVE)
      ret = SapModel.LoadPatterns.Add("NEISHUIYALI", LTYPE_LIVE)
      ret = SapModel.LoadPatterns.Add("WENDUHEZAI", LTYPE_LIVE)
      ret = SapModel.LoadPatterns.Add("ZIZHONG", LTYPE_DEAD, 1) '自重系数为1

'5.定义荷载工况:正常运行①  正常运行②  机组检修    完建蓄水前  机组未安装①    机组未安装②    非常运行    地震情况
'完建情况        正常蓄水位情况      设计洪水位情况      冰冻情况        施工情况        检修情况        校核洪水情况        地震情况        下游最低水位情况

   'add static linear load case
      'ret = SapModel.LoadCases.StaticLinear.SetCase("WANJIANWUTU")
      ret = SapModel.LoadCases.StaticLinear.SetCase("WUNEISHUI")
      ret = SapModel.LoadCases.StaticLinear.SetCase("YOUNEISHUI")
      'ret = SapModel.LoadCases.StaticLinear.SetCase("TIANTU")
   'add static linear load case
      'ret = SapModel.LoadCases.StaticLinear.SetCase("LCASE1")
   'set load data
      ReDim MyLoadType(4)
      ReDim MyLoadName(4)
      ReDim MySF(4)
      MyLoadType(0) = "Load"
      MyLoadName(0) = "CETUYALI"
      MySF(0) = 0

      MyLoadType(1) = "Load"
      MyLoadName(1) = "DIXIASHUIYALI"
      MySF(1) = 0

      MyLoadType(2) = "Load"
      MyLoadName(2) = "DIXIASHUIFULI"
      MySF(2) = 0

      MyLoadType(3) = "Load"
      MyLoadName(3) = "WENDUHEZAI"
      MySF(3) = 0

      MyLoadType(4) = "Load"
      MyLoadName(4) = "ZIZHONG"
      MySF(4) = 1
      ret = SapModel.LoadCases.StaticLinear.SetLoads("WUNEISHUI", 5, MyLoadType, MyLoadName, MySF)

      ReDim Preserve MyLoadType(5)
      ReDim Preserve MyLoadName(5)
      ReDim Preserve MySF(5)

      MyLoadType(5) = "Load"
      MyLoadName(5) = "NEISHUIYALI"
      MySF(5) = 0

      ret = SapModel.LoadCases.StaticLinear.SetLoads("YOUNEISHUI", 5, MyLoadType, MyLoadName, MySF)
      ret = SapModel.LoadCases.Delete("DEAD")
      ret = SapModel.LoadPatterns.Delete("DEAD")
   'get load data
      'ret = SapModel.LoadCases.StaticLinear.GetLoads("LCASE1", NumberLoads, LoadType, LoadName, SF)
'   'add static linear load case
'      ret = SapModel.LoadCases.StaticLinear.SetCase("LCASE1")

'6.定义荷载组合:基本组合        特殊组合Ⅰ                  特殊组合Ⅱ

   'add combo
      'ret = SapModel.RespCombo.Add("COMB1", 0) '0 = Linear Additive
   'add load case to combo
      'ret = SapModel.RespCombo.SetCaseList("COMB1", LoadCase, "DEAD", 1.4) 'LoadCase = 0 LoadCombo = 1

'7.建立模型,同时确定截面
   'define new coordinate system
'      ret = SapModel.CoordSys.SetCoordSys("CSys1", 1000, 1000, 0, 0, 0, 0)
   'add point object to model
   '1先通过柱坐标生成点;无法直接用柱坐标生成面?没提供这个功能
      Dim N As Integer
      N = Int(Application.Pi() * 2 * R0)
      z = 0
      Theta1 = 360 / N
      ReDim PointName(0 To N - 1) '!非常奇怪,必须是从0开始,否则后面AreaObj.AddByPoint无法生成面
      For i = 0 To N - 1
      Theta2 = Theta1 * i
      PointName(i) = "P" & i
      ret = SapModel.PointObj.AddCylindrical(R0, Theta2, z, Name, PointName(i))
      Next i
 '生成底板
      UserName = "A1"
      ret = SapModel.AreaObj.AddByPoint(N, PointName, Name, "DIBAN", UserName)

      ReDim FrameName(0 To N - 1)
      For i = 0 To N - 2
   'add frame object by points
      FrameName(i) = "F" & i
      ret = SapModel.FrameObj.AddByPoint(PointName(i), PointName(i + 1), FrameName(i))
      Next i
      FrameName(i) = "F" & i
      ret = SapModel.FrameObj.AddByPoint(PointName(0), PointName(i), FrameName(i))
   'linearly extrude frame to areas拉伸线成面
   For i = 0 To N - 1
   ret = SapModel.EditGeneral.ExtrudeFrameToAreaLinear(FrameName(i), "CEQIANG", 0, 0, 1, Int(H0), AreaName, True)
   Next i
   '!不能一次性将全部杆件拉伸成面,下行代码无效。
   'ret = SapModel.EditGeneral.ExtrudeFrameToAreaLinear("All", "CEQIANG", 0, 0, 1, Int(H0), AreaName, True)

   '2点生成面——每个面要赋名称A1~An
   'add area object by points
      ReDim Point(8)
      Point(0) = "P1"
      Point(1) = "P2"
      Point(2) = "P3"
      Point(3) = "P4"
      Point(4) = "P5"
      Point(5) = "P6"
      Point(6) = "P7"
      Point(7) = "P8"
      Point(8) = "P9"
'生成底板
'Dim m As Long
'm = 63
'UserName = "A1"
'      ret = SapModel.AreaObj.AddByPoint(9, PointName, Name, "DIBAN", UserName)
   '3网格化——必须给每个面赋予名称B1~Bn,方便后面施加荷载divide area object
      'ret = SapModel.EditArea.Divide("1", 1, NumberAreas, AreaName, n1, n2)

   '4施加荷载assign area object surface pressure load
   '由于没有提供柱坐标下选择面的类,所以只能通过面的名称来选择面
      ret = SapModel.AreaObj.SetLoadSurfacePressure("Name", "DEAD", -1, 0.1, , , Object)

'8.覆盖材料和厚度assign material overwrite
'      ret = SapModel.AreaObj.SetMaterialOverwrite("3", "A992Fy50")
'侧墙变厚度——用面厚度覆盖
'    'assign thickness overwrites
'      ReDim Thickness(3)
'      For i = 0 To 3
'         Thickness(i) = 11
'      Next i
'      ret = SapModel.AreaObj.SetThickness("ALL", 2, "", 1, Thickness, Group)
'9.添加面弹簧
   'assign springs to area objects面弹簧
      ReDim Vec(2)
      ret = SapModel.AreaObj.SetSpring("1", 1, K0, 1, "", -1, 2, 1, True, Vec, 0, True, , Object) '中括号的可以省略,其他似乎不可省略。
      'ret = SapModel.AreaObj.SetSpring("1", 1, K0, 1, -1, 2, 1, True, True, "Local", Object)
   'ret = SapModel.AreaObj.SetSpring("ALL", 1, 1,  1, "", -1, 1, 3, True, Vec, 0, False, "Local", Group)
'.网格化 面单元推荐采用自动网格化,好处是不会产生很多节点以及很多面,方便施加荷载,或者施加荷载后再划分网格
'   'assign auto mesh options
'     ret = SapModel.AreaObj.SetAutoMesh("ALL", 1, 3, 3, , , , , , , , , , , , , , , Group)
'   'refresh view
'      ret = SapModel.View.RefreshView(0, False)
'.添加约束:节点、面
 'Function SetSpring(ByVal Name As String,
 'ByVal MyType As Long,
 'ByVal s As Double,
 'ByVal SimpleSpringType As Long,
 'ByVal LinkProp As String,
 'ByVal Face as Long,
 'ByVal SpringLocalOneType As Long,
 'ByVal Dir As Long,
 'ByVal Outward As Boolean,
 'ByRef Vec() As Double,
 'ByVal Ang As Double,
 'ByVal Replace As Boolean,
 'Optional ByVal CSys As String = "Local",
 'Optional ByVal ItemType As eItemType = Object) As Long
   'assign point object restraints
'      ReDim VALUE(5)
'      For i = 0 To 5
'         VALUE(i) = True
'      Next i
'      ret = SapModel.PointObj.SetRestraint("1", VALUE)
'
'   'assign spring to a point
'      ReDim k(5)
'      k(2) = 10
'      ret = SapModel.PointObj.SetSpring("3", k)
'
'   'assign springs to area objects面弹簧
'      ReDim Vec(2)
'      ret = SapModel.AreaObj.SetSpring("ALL", 1, 1, 1, "", -1, 1, 3, True, Vec, 0, False, "Local", Group)
'
'10.对面单元施加面弹簧约束后,进行网格划分,
'自动网格化很方便,好处是网格划分前后还是保持一个面,因此并未增加面标签。
'划分网格前施加节点样式荷载,划分网格后会丢失!其他面荷载不受影响。所以节点荷载一定要在网格划分后再施加。
   'divide area object
     ret = SapModel.EditArea.Divide("1", 1, NumberAreas, AreaName, L0, B0)
     ret = SapModel.EditArea.Divide("2", 1, NumberAreas, AreaName, L0, H0)
     ret = SapModel.EditArea.Divide("3", 1, NumberAreas, AreaName, L0, H0)
     ret = SapModel.EditArea.Divide("4", 1, NumberAreas, AreaName, B0, H0)
     ret = SapModel.EditArea.Divide("5", 1, NumberAreas, AreaName, B0, H0)
'   'assign auto mesh options
'     ret = SapModel.AreaObj.SetAutoMesh("1", 1, L0, B0)
'     ret = SapModel.AreaObj.SetAutoMesh("2", 1, L0, H0)
'     ret = SapModel.AreaObj.SetAutoMesh("3", 1, L0, H0)
'     ret = SapModel.AreaObj.SetAutoMesh("4", 1, B0, H0)
'     ret = SapModel.AreaObj.SetAutoMesh("5", 1, B0, H0)
'11.添加节点样式数据
   'add joint pattern assignment
      ret = SapModel.PointObj.SetPatternByXYZ("ALL", "DIXIASHUI", 0, 0, -1, H0, Group, , True) '用“ALL”则必须对应Group啊!
      ret = SapModel.PointObj.SetPatternByXYZ("ALL", "TIANTU", 0, 0, -1, H0, Group, , True)
      'Value = ax + by + cz + d
'水平面处压力为零,水平面以下各点的压力仅与水的重度和水深有关,即p = γ( H2 - Zj ).
'因此,在定义节点样式V = Ax+By+Cz+D 时,由于压力梯度仅与Z 坐标有关,故A=B = O,C=-l,D = 高度(H2O)

'12.添加荷载
   'assign area object surface pressure load设置节点样式荷载也是这个,输入乘数γ=9.81.
      '侧墙水压力
   'select in XY plane
      ret = SapModel.SelectObj.PlaneXZ("1")
      ret = SapModel.AreaObj.SetLoadSurfacePressure("2", "DIXIASHUIYALI", -2, 10, "DIXIASHUI", True, SelectedObjects)
      ret = SapModel.AreaObj.SetLoadSurfacePressure("2", "CETUYALI", -2, K1, "TIANTU", True, SelectedObjects) '注意,这里K1包含了土的浮容重!
   'clear selection
      ret = SapModel.SelectObj.ClearSelection

      ret = SapModel.SelectObj.PlaneXZ("4")
      ret = SapModel.AreaObj.SetLoadSurfacePressure("3", "DIXIASHUIYALI", -1, 10, "DIXIASHUI", True, SelectedObjects)
      ret = SapModel.AreaObj.SetLoadSurfacePressure("3", "CETUYALI", -1, K1, "TIANTU", True, SelectedObjects)
   'clear selection
      ret = SapModel.SelectObj.ClearSelection

      ret = SapModel.SelectObj.PlaneYZ("3")
      ret = SapModel.AreaObj.SetLoadSurfacePressure("4", "DIXIASHUIYALI", -2, 10, "DIXIASHUI", True, SelectedObjects)
      ret = SapModel.AreaObj.SetLoadSurfacePressure("4", "CETUYALI", -2, K1, "TIANTU", True, SelectedObjects)
   'clear selection
      ret = SapModel.SelectObj.ClearSelection

      ret = SapModel.SelectObj.PlaneYZ("1")
      ret = SapModel.AreaObj.SetLoadSurfacePressure("5", "DIXIASHUIYALI", -1, 10, "DIXIASHUI", True, SelectedObjects)
      ret = SapModel.AreaObj.SetLoadSurfacePressure("5", "CETUYALI", -1, K1, "TIANTU", True, SelectedObjects)
      '侧墙填土(浮容重)压力
   'clear selection
      ret = SapModel.SelectObj.ClearSelection
      '底板底部水浮力
      ret = SapModel.SelectObj.PlaneXY("1")
      ret = SapModel.AreaObj.SetLoadSurfacePressure("1", "DIXIASHUIFULI", -1, 10 * H0, , True, SelectedObjects)
   'clear selection
      ret = SapModel.SelectObj.ClearSelection
'   'assign area object gravity loads
'      ret = SapModel.AreaObj.SetLoadGravity("ALL", "DEAD", 0, 0, -1, , , Group)
'   'assign area object wind pressure load
'      ret = SapModel.AreaObj.SetLoadWindPressure("ALL", "DEAD", 1, 0.8, Group)
'   'assign area object temperature load
'      ret = SapModel.AreaObj.SetLoadTemperature("All", "DEAD", 1, 50, , , Group)

'13.分析
   'save model必须在运行前保存
   '保存模型
   '  SapModel.File.Save (ModelName)
      ret = SapModel.File.Save("C:\SapAPI\fajing.sdb")
   'create the analysis model
      ret = SapModel.Analyze.CreateAnalysisModel
   'set load case run flag
      ret = SapModel.Analyze.SetRunCaseFlag("MODAL", False)
   'set model solver options
      ret = SapModel.Analyze.SetSolverOption_1(1, 1, True, "")
   'run model (this will create the analysis model)
      ret = SapModel.Analyze.RunAnalysis
'14.分析结果

'15.设计配筋

'16.关闭
   'close Sap2000
'      SapObject.ApplicationExit False
'      Set SapModel = Nothing
'      Set SapObject = Nothing
End Sub
作者:秦晓川  创建时间:2020-09-08 18:24
最后编辑:秦晓川  更新时间:2021-12-19 22:12