Continue to Site

Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

  • Congratulations SSS148 on being selected by the Eng-Tips community for having the most helpful posts in the forums last week. Way to Go!

ETABS api VBA code for making changes in existing modal of etabs

Status
Not open for further replies.

ENGKHURRAMALI

Civil/Environmental
Feb 8, 2016
2
Dear all,

I have question that , is there any way i can connect my existing modal of etabs to excel vba through API. I wand to modify load combination , my modal have already combos , i want to replace it with new one

I have found some vba code in ETABS refrence file , but it create a new model and i want to modify an existing model , code is below as:
''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Public Sub Example()
Dim SapModel As cSapModel
Dim EtabsObject As cOAPI
Dim ret As Integer = -1
Dim Selected As Boolean

'create ETABS object
EtabsObject = CreateObject("CSI.ETABS.API.ETABSObject")

'start ETABS application
ret = EtabsObject.ApplicationStart()

'create SapModel object
SapModel = EtabsObject.SapModel

'initialize model
ret = SapModel.InitializeNewModel()

'create steel deck template model
ret = SapModel.File.NewSteelDeck(4,12,12,4,4,24,24)

'add combo
ret = SapModel.RespCombo.Add("COMB1", 0)

'add load case to combo
ret = SapModel.RespCombo.SetCaseList("COMB1", eCNameType.LoadCase, "DEAD", 1.4)

'run analysis
System.IO.Directory.CreateDirectory("c:\CSI_API_temp")
ret = SapModel.File.Save("C:\CSI_API_temp\example.edb")
ret = SapModel.Analyze.RunAnalysis

'deselect all cases and combos
ret = SapModel.Results.Setup.DeselectAllCasesAndCombosForOutput

'set combo selected for output
ret = SapModel.Results.Setup.SetComboSelectedForOutput("COMB1")

'check if combo is selected
ret = SapModel.Results.Setup.GetComboSelectedForOutput("COMB1", Selected)

'close ETABS
EtabsObject.ApplicationExit(False)

'clean up variables
SapModel = Nothing
EtabsObject = Nothing
End Sub
''''''''''''''''''''''''''''''''''''''''''''''''''''''''

can any suggest me to modify above code for existing model

thanks in advance
 
Replies continue below

Recommended for you

Instead of these two:
--------------------------------------------------------------------------------
'create ETABS object
EtabsObject = CreateObject("CSI.ETABS.API.ETABSObject")

'start ETABS application
ret = EtabsObject.ApplicationStart()[/indent]
--------------------------------------------------------------------------------

You need the following lines in order to attach to the existing model:
--------------------------------------------------------------------------------
'attach to a running instance of ETABS
'get the active ETABS object
Set EtabsObject = GetObject(, "CSI.ETABS.API.ETABSObject")

'get a reference to cSapModel to access all OAPI classes and functions
Set SapModel = EtabsObject.SapModel
--------------------------------------------------------------------------------

Also, the following lines will create a new instance and use a template, so you need to delete or add a switch to these in order to use your existing model:
--------------------------------------------------------------------------------
'initialize model
ret = SapModel.InitializeNewModel()

'create steel deck template model
ret = SapModel.File.NewSteelDeck(4,12,12,4,4,24,24)
--------------------------------------------------------------------------------

The final result should look like this:
--------------------------------------------------------------------------------
Public Sub Example()
Dim SapModel As cSapModel
Dim EtabsObject As cOAPI
Dim ret As Integer = -1
Dim Selected As Boolean

Set EtabsObject = Nothing
Set EtabsObject = GetObject(, "CSI.ETABS.API.ETABSObject")
Set SapModel = EtabsObject.SapModel

'add combo
ret = SapModel.RespCombo.Add("COMB1", 0)

'add load case to combo
ret = SapModel.RespCombo.SetCaseList("COMB1", eCNameType.LoadCase, "DEAD", 1.4)

'run analysis
System.IO.Directory.CreateDirectory("c:\CSI_API_temp")
ret = SapModel.File.Save("C:\CSI_API_temp\example.edb")
ret = SapModel.Analyze.RunAnalysis

'deselect all cases and combos
ret = SapModel.Results.Setup.DeselectAllCasesAndCombosForOutput

'set combo selected for output
ret = SapModel.Results.Setup.SetComboSelectedForOutput("COMB1")

'check if combo is selected
ret = SapModel.Results.Setup.GetComboSelectedForOutput("COMB1", Selected)

'close ETABS
EtabsObject.ApplicationExit(False)

'clean up variables
SapModel = Nothing
EtabsObject = Nothing
End Sub
--------------------------------------------------------------------------------

Good luck!
 
IS THERE A WAY BY WHICH I CAN SELECT MODEL , BY SOME POPUP WINDOW , I DONT WANT TO ATTACHED ACTIVE MODEL , I HAVE SO MANY MODEL , SO I WANT TO ATTACHED A PARTICULAR ONE , IS THIS POSSIBLE
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor