- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hello All,
I am trying to work out a way, by running a macro in excel, to be able to:
1.Open a specific Robot file (that has not been "calculated" or analysed" before (just set up with loads, section types, etc).
2.Run the calculations in it (i.e. RobApp.Project.CalcEngine.Calculate)
3.Run the steel member verification ULS (i.e .Solve Nothing)
4.Save the "calculated" Robot file (and its verification ULS results), and Close it.
My aim is for these 4 tasks to be instructed from a VBA macro in an excel file.
The purpose of this is to be able to make changes to multiple .rtd files from within Robot (e.g. changing intensity of the loads applied), be able to generate analysis results and Eurocode steel capacity ratios running the models as a batch overnight and then access the results in Robot, including capacity ratio and detailed section results for each of the files the following morning. We would like to be able to view capacity ratio maps on bars
I am only just starting with Robot API and had a go using the VBA excel file that Rafal kindly uploaded in this forum
I have just added some lines so to recreate the series of tasks mentioned above (Please find files attached).
My hunch is that the robot file is not storing the results of the calculations undergone for the verification process.
I believe that this should be done by using the IRDimClient mode (and probably the IRDimMembCalc together with its CalculMember method) but I have not found any example on how to implement these. If you could please point me in the right direction, or even if there is an example on how to use these methods, it will be much appreciated.
Many thanks!
Best wishes,
Maria
-- (Code below..!)
Public RobApp As RobotApplication
Public Sub OpenRunSavesAs_RatioAlongBar_1()
Range("A13", "L25000").Clear
'Range("B5").Clear
If (ActiveSheet.ChartObjects.Count <> 0) Then
ActiveSheet.ChartObjects.Delete
Application.DisplayAlerts = True
End If
Set RobApp = New RobotApplication
If Not RobApp.Visible Then
Set RobApp = Nothing
MsgBox "Open Robot Please! ", vbOKOnly, "ERROR"
Exit Sub
End If
If (RobApp.Project.Type <> I_PT_FRAME_3D) And (RobApp.Project.Type <> I_PT_SHELL) And (RobApp.Project.Type <> I_PT_BUILDING) Then
MsgBox "Structure Type should be FRAME 3D or SHELL or BUILDING", vbOKOnly, "ERROR"
Exit Sub
End If
'--1.Open a specific Robot file (that has not been "calculated" or analysed" before (just set up with loads, section types, etc).
' Cells(5, 1) = "Project"
' Cells(5, 2) = RobApp.Project.Name
Dim g1, g2 As String
Dim StartFile, EndFile As Integer
EndFile = 4
For StartFile = 4 To EndFile
g1 = Range("B" & StartFile).Text
g2 = Range("B" & StartFile + 1).Text
g1 = g1 & ".rtd"
g2 = g2 & ".rtd"
RobApp.Project.Open (g1)
Dim RSelection As RobotSelection
Set RSelection = RobApp.Project.Structure.Selections.Create(I_OT_BAR)
Dim BarCol As RobotBarCollection
If (Cells(8, 2) <> "") Then
RSelection.FromText Cells(8, 2)
Set BarCol = RobApp.Project.Structure.Bars.GetMany(RSelection)
Else
If (MsgBox("No bars in selection cell B8. Do you want to import results for all bars?", vbYesNo, "Warning") = vbYes) Then
RSelection.FromText "all"
RSelection.AddText "tous"
Set BarCol = RobApp.Project.Structure.Bars.GetMany(RSelection)
Else
Set BarCol = Nothing
Exit Sub
End If
End If
If (BarCol.Count = 0) Then
If (MsgBox("No bars selected. Do you want to import results for all bars?", vbYesNo, "Warning") = vbYes) Then
RSelection.FromText "all"
RSelection.AddText "tous"
Set BarCol = RobApp.Project.Structure.Bars.GetMany(RSelection)
Else
Set BarCol = Nothing
Exit Sub
End If
End If
Cells(8, 1) = "Bars"
Cells(8, 2) = RSelection.ToText
Set RSelection = RobApp.Project.Structure.Selections.Create(I_OT_CASE)
Dim CaseCol As RobotCaseCollection
If (Cells(9, 2) <> "") Then
RSelection.FromText Cells(9, 2)
Set CaseCol = RobApp.Project.Structure.Cases.GetMany(RSelection)
Else
If (MsgBox("No cases in selection cell B9. Do you want to import results for all cases?", vbYesNo, "Warning") = vbYes) Then
RSelection.FromText "all"
RSelection.AddText "tous"
Set CaseCol = RobApp.Project.Structure.Cases.GetMany(RSelection)
Else
Set CaseCol = Nothing
Exit Sub
End If
End If
Dim Div As Long
If (Cells(10, 2) <> "" And Cells(10, 2) >= 3) Then
Div = Cells(10, 2)
Else
MsgBox "Wrong value of number of calculation points in cell B10. Value should be greater or equal to 3", vbCritical, "Error"
Exit Sub
End If
If (CaseCol.Count = 0) Then
If (MsgBox("No cases selected. Do you want to import results for all cases?", vbYesNo, "Warning") = vbYes) Then
RSelection.FromText "all"
RSelection.AddText "tous"
Set CaseCol = RobApp.Project.Structure.Cases.GetMany(RSelection)
Else
Set BarCol = Nothing
Exit Sub
End If
End If
Cells(9, 1) = "Load cases"
Cells(9, 2) = RSelection.ToText
If (RobApp.Project.Structure.Results.Available = False) Then
If (MsgBox("Results not available. Do you want to start calculations ?", vbYesNo, "Error") = vbYes) Then
RobApp.Project.CalcEngine.Calculate
Else
Exit Sub
End If
End If
Row = 13
Cells(12, 1) = "Bar"
Cells(12, 2) = "Case"
Cells(12, 3) = "Point"
Cells(12, 4) = "Ratio"
Cells(12, 5) = "Lay"
Cells(12, 6) = "Laz"
Cells(12, 11) = "Profile"
Cells(12, 12) = "Material"
Cells(8, 4) = "Progress"
Dim RDMServer As IRDimServer
Set RDMServer = RobApp.Kernel.GetExtension("RDimServer")
RDMServer.Mode = I_DSM_STEEL
Dim RDmEngine As IRDimCalcEngine
Set RDmEngine = RDMServer.CalculEngine
Dim StartRowChart As Long, EndRowChart As Long
For i = 1 To BarCol.Count
Cells(8, 5) = Str(i) + " / " + Str(BarCol.Count)
'the part below is optional, use it if you want to set calculation parameters by the code
Dim RDmCalPar As IRDimCalcParam
Dim RDmCalCnf As IRDimCalcConf
Set RDmCalPar = RDmEngine.GetCalcParam
Set RDmCalCnf = RDmEngine.GetCalcConf
Dim RdmStream As IRDimStream 'Data stream for setting parameters
Set RdmStream = RDMServer.Connection.GetStream
RdmStream.Clear
'Calculate results for all sections
'aaa = BarCol.Get(i).Number
RdmStream.WriteText (Str(BarCol.Get(i).Number)) ' member(s) selection
RDmCalPar.SetObjsList I_DCPVT_MEMBERS_VERIF, RdmStream 'members verification
RDmCalPar.SetLimitState I_DCPLST_ULTIMATE, 1 'Set Limit State
RdmStream.Clear
'aaa = Trim(RSelection.ToText)
RdmStream.WriteText Trim(RSelection.ToText) 'Set Load Case(s)
RDmCalPar.SetLoadsList RdmStream
Dim RelL As Double, inc As Double
RelL = 0
inc = 1# / (Div - 1)
Cells(Row, 1) = BarCol.Get(i).Number
StartRowChart = Row
RDmCalCnf.SetFlag I_DCCFT_CHARPOINTS, 1
RDmCalCnf.SetFlag I_DCCFT_USERPOINTS, 1
RDmCalCnf.SetFlag I_DCCFT_N_AND_CHAR_POINTS, 0
RDmCalCnf.SetFlag I_DCCFT_MAX_FX_POINT, 0
RDmCalCnf.SetFlag I_DCCFT_MAX_FY_POINT, 0
RDmCalCnf.SetFlag I_DCCFT_MAX_FZ_POINT, 0
RDmCalCnf.SetFlag I_DCCFT_MAX_MY_POINT, 0
RDmCalCnf.SetFlag I_DCCFT_MAX_MZ_POINT, 0
For j = 1 To Div
Cells(Row, 3) = RelL
'bbb = RDmCalCnf.IsFlagSet(I_DCCFT_CHARPOINTS)
RDmCalCnf.ClearUserCharPoints
RDmCalCnf.WriteUserCharPoint RelL
'aaa = RDmCalCnf.ReadUserCharPoint(1)
RelL = RelL + inc
Dim RDmDetRes As IRDimDetailedRes
Dim RDMAllRes As IRDimAllRes
RDmEngine.SetCalcConf RDmCalCnf
RDmEngine.SetCalcParam RDmCalPar
'end of calculation parameter settings
RDmEngine.Solve Nothing
Set RDMAllRes = RDmEngine.Results
Set RDmDetRes = RDMAllRes.Get(BarCol.Get(i).Number)
If RDmDetRes.IsLimitStateUltimate Then
Cells(Row, 2) = RDmDetRes.GovernCaseName
Cells(Row, 4) = RDmDetRes.Ratio
Cells(Row, 5) = RDmDetRes.Lay 'added from DesignSteel-RobotAPI
Cells(Row, 6) = RDmDetRes.Laz
End If
Cells(Row, 11) = RDmDetRes.ProfileName
Cells(Row, 12) = RDmDetRes.MaterialName
'171204_here needs something so to ask Robot File to save the results of verification/calculation -ie. CalculMember ()...?
Row = Row + 1
'Set RDmDetRes = Nothing
'Set RDMAllRes = Nothing
Next j
EndRowChart = Row - 1
Macro1 StartRowChart, EndRowChart
Next i
Cells(8, 4) = ""
Cells(8, 5) = ""
'--4.Save the "calculated" Robot file (and its verification ULS results), and Close it.
RobApp.Project.SaveAs (g2) '171204_so to save the file and fater, when re opening and changing intensity of loads, by re-running this macro, Robot can show values of "Map for Bars" consistent with updated verification results(which is not doing at the moment...)
'RobApp.Project.Close
Next StartFile
End Sub
Solved! Go to Solution.
