I am new to Openstaad and am trying to develop a macro in Openstaad to get Plate center stresses and moments corresponding to Maximum Bending moment,(Sagging/Hogging, Mx/My) for selected plates and selected number of Loadcases. There are two major issues I am facing
1) The command for extracting Plate Center stresses and moments in Openstaad is getallplatecenterstressesandmoments(plate_number, loadcase_number, lplatecenterstressesandmoments), where lplatecenterstressesandmoments is an array of size 8.When I am taking the Data type of lplatecenterstressesandmoments as Long, all the stresses and moments are zero. When I am taking the Datatype of lplatecenterstressesandmoments as Double, then I am getting an error saying " Array Index out of Range", whenever I am trying to address any element of that array.
2) If I want to use the results for my slab or wall design, then how do I link the final array consisting of results to my design spreadsheets
Please find below my code, I have highlighted the line where the problem is. I have added a lot of Message boxes in the code for my own checks, you can ignore them. Please got through it and help me out. Thanks in advance
Sub Main()'DESCRIPTION:Description of the macro goes hereDim loadcase_lower As StringDim loadcase_upper As StringDim ListArray1(0 To 1) As StringDim ListArray2(0 To 1) As String
ListArray1(0)="Mx"ListArray1(1)="My"ListArray2(0)="Max"ListArray2(1)="Min" Begin Dialog UserDialog 400,203 ' %GRID:10,7,1,1 TextBox 230,14,60,21,.TextBox1 Text 30,14,130,21,"Loadcase Lower = ",.Text1 Text 30,56,130,21,"Loadcase Upper = ",.Text2 TextBox 230,49,60,21,.TextBox2 DropListBox 40,98,90,21,ListArray1(),.DropListBox1 DropListBox 240,98,90,21,ListArray2(),.DropListBox2 OKButton 120,140,80,21 End Dialog Dim dlg As UserDialog Dialog dlg
loadcase_lower=dlg.textbox1loadcase_upper=dlg.textbox2
Dim loadcase_lint As Longloadcase_lint =CInt(loadcase_lower)Dim loadcase_uint As Longloadcase_uint =CInt(loadcase_upper)
Dim staad As ObjectDim no_loadcases_total, no_loadcases As LongDim lcenterstressesarray(0 To 7) As LongDim templcenterstressesarray(0 To 7) As LongDim checker,tempchecker As DoubleDim i,j,k,ind, plate_id,loadcase_id,no_selplates As Long
If dlg.Droplistbox1=0 Thenind=2Elseind=3End If
Set staad=GetObject(,"staadpro.openstaad")no_selplates=staad.geometry.getnoofselectedplatesReDim selplates(0 To no_selplates-1) As Longstaad.geometry.getselectedplates selplatesMsgBox "the no of selected plates" &no_selplates, vbOkOnly
no_loadcases_total=staad.load.getprimaryloadcasecountReDim loadcase_total(0 To no_loadcases_total-1) As Longstaad.load.getprimaryloadcasenumbers loadcase_total
no_loadcases=loadcase_uint-loadcase_lint+1MsgBox "no_loadcases:" &no_loadcasesReDim loadcase(0 To no_loadcases-1) As LongFor i=0 To no_loadcases-1loadcase(i)=loadcase_total(loadcase_lint -1+i)Next i
plate_id=selplates(0)loadcase_id=loadcase(0)
staad.Output.getallplatecenterstressesandmoments(plate_id,loadcase_id,templcenterstressesarray)If templcenterstressesarray(ind)>0 Thenchecker=templcenterstressesarray(ind)+Abs(templcenterstressesarray(4))Elsechecker=templcenterstressesarray(ind)-Abs(templcenterstressesarray(4))End If
For i=1 To no_selplates-1For j=0 To no_loadcases-1plate_id=selplates(i)loadcase_id=loadcase(j)staad.Output.getallplatecenterstressesandmoments(selplates(i),loadcase(j),lcenterstressesarray)
If lcenterstressesarray(ind)>0 Thentempchecker=lcenterstressesarray(ind)+Abs(lcenterstressesarray(4))Elsetempchecker=lcenterstressesarray(ind)-Abs(lcenterstressesarray(4))End If
If dlg.droplistbox2=0 Then If tempchecker>checker Then checker=tempcheker plate_id=selplates(i) loadcase_id=loadcase(j) For k=0 To 7 templcenterstressesarray(k)=lcenterstressesarray(k) Next k 'Else 'checker=checker 'plate_id=plate_id 'loadcase_id=loadcase_id 'templcenterstressesarray=templcenterstressesarray End IfElse If tempchecker<checker Then checker=tempcheker plate_id=selplates(i) loadcase_id=loadcase(j) For k=0 To 7 templcenterstressesarray(k)=lcenterstressesarray(k) Next k 'Else 'checker=checker 'plate_id=plate_id 'loadcase_id=loadcase_id 'templcenterstressesarray=templcenterstressesarray End IfEnd IfNext jNext i
MsgBox "plate_id" &plate_idMsgBox "loadcase_id" &loadcase_idFor i=0 To 7MsgBox "load:" &templcenterstressesarray(i)Next i
'TODO: Add your code here
End Sub
Sudip Narayan Choudhury
Hi,
I have reviewed your code. The problem was with the following command lines--
staad.Output.getallplatecenterstressesandmoments(plate_id,loadcase_id,templcenterstressesarray)If templcenterstressesarray(ind)>0 Then
I have modified the code and also changed the variable type of the stress array to Double and now the correct values are reported. I have attached the code in .txt format. Change the extension to .vbs and import the same in STAAD.
Sub Main() Dim loadcase_lower As String Dim loadcase_upper As String Dim ListArray1(0 To 1) As String Dim ListArray2(0 To 1) As String ListArray1(0)="Mx" ListArray1(1)="My" ListArray2(0)="Max" ListArray2(1)="Min" Begin Dialog UserDialog 400,203 ' %GRID:10,7,1,1 TextBox 230,14,60,21,.TextBox1 Text 30,14,130,21,"Loadcase Lower = ",.Text1 Text 30,56,130,21,"Loadcase Upper = ",.Text2 TextBox 230,49,60,21,.TextBox2 DropListBox 40,98,90,21,ListArray1(),.DropListBox1 DropListBox 240,98,90,21,ListArray2(),.DropListBox2 OKButton 120,140,80,21 End Dialog Dim dlg As UserDialog Dialog dlg loadcase_lower=dlg.textbox1 loadcase_upper=dlg.textbox2 Dim loadcase_lint As Long loadcase_lint =CInt(loadcase_lower) Dim loadcase_uint As Long loadcase_uint =CInt(loadcase_upper) Dim staad As Object Dim no_loadcases_total, no_loadcases As Long Dim lcenterstressesarray(0 To 7) As Double Dim templcenterstressesarray(0 To 7) As Double Dim checker,tempchecker As Double Dim i,j,k,ind, plate_id,loadcase_id,no_selplates As Long If dlg.Droplistbox1=0 Then ind=2 Else ind=3 End If Set staad=GetObject(,"staadpro.openstaad") no_selplates=staad.geometry.getnoofselectedplates ReDim selplates(0 To no_selplates-1) As Long staad.geometry.getselectedplates selplates MsgBox "the no of selected plates" &no_selplates, vbOkOnly no_loadcases_total=staad.load.getprimaryloadcasecount ReDim loadcase_total(0 To no_loadcases_total-1) As Long staad.load.getprimaryloadcasenumbers loadcase_total no_loadcases=loadcase_uint-loadcase_lint+1 MsgBox "no_loadcases:" &no_loadcases ReDim loadcase(0 To no_loadcases-1) As Long For i=0 To no_loadcases-1 loadcase(i)=loadcase_total(loadcase_lint -1+i) Next i i = 0 j = 0 staad.Output.getallplatecenterstressesandmoments (selplates(i), loadcase(j), templcenterstressesarray) If templcenterstressesarray(ind)>0 Then checker=templcenterstressesarray(ind)+Abs(templcenterstressesarray(4)) Else checker=templcenterstressesarray(ind)-Abs(templcenterstressesarray(4)) End If For i=1 To no_selplates-1 For j=0 To no_loadcases-1 plate_id=selplates(i) loadcase_id=loadcase(j) staad.Output.getallplatecenterstressesandmoments(selplates(i),loadcase(j),lcenterstressesarray) If lcenterstressesarray(ind)>0 Then tempchecker=lcenterstressesarray(ind)+Abs(lcenterstressesarray(4)) Else tempchecker=lcenterstressesarray(ind)-Abs(lcenterstressesarray(4)) End If If dlg.droplistbox2=0 Then If tempchecker>checker Then checker=tempcheker plate_id=selplates(i) loadcase_id=loadcase(j) For k=0 To 7 templcenterstressesarray(k)=lcenterstressesarray(k) Next k 'Else 'checker=checker 'plate_id=plate_id 'loadcase_id=loadcase_id 'templcenterstressesarray=templcenterstressesarray End If Else If tempchecker<checker Then checker=tempcheker plate_id=selplates(i) loadcase_id=loadcase(j) For k=0 To 7 templcenterstressesarray(k)=lcenterstressesarray(k) Next k 'Else 'checker=checker 'plate_id=plate_id 'loadcase_id=loadcase_id 'templcenterstressesarray=templcenterstressesarray End If End If Next j Next i MsgBox "plate_id" &plate_id MsgBox "loadcase_id" &loadcase_id For i=0 To 7 MsgBox "load:" &templcenterstressesarray(i) Next i End Sub
Answer Verified By: Aravind Basavaraju
You can export the results to excel using the same code. One method to export the results to excel is to create a macro enabled excel file (extension .xlsm) and add your code in that excel. You can add a ActiveX control button in the excel and add your code there. You can select the inputs from the excel cells and also extract the values to excel cells. For that, you need to modify your code accordingly. I have added your code in the attached excel file. You need to open only the relevant .std file first and then open the excel and click on the Plate stress tab to extract the results.Plate Center Stress.zip
Hi Suro, I am trying to extract all plate stresses in staad pro, But I am stuck in between Could you please provide me code to extract staad plate stress for all load cases?? and also I am attaching excel sheet which I am developing
Sub PLATEMOMENT() Dim lLoadCase As Long Dim objOpenSTAAD As Object Dim SelPlatesNo As Long Dim SelPlates() As Long 'Get the application object -- 'Get no. of selected plates Dim lcenterstressesarray(1 To 8) As Double Dim dCenterStressesArray(1 To 8) As Double Dim templcenterstressesarray(1 To 7) As Double Set objOpenSTAAD = GetObject(, "StaadPro.OpenSTAAD") SelPlatesNo = objOpenSTAAD.Geometry.GetNoOfSelectedPlates 'Reallocate ReDim SelPlates(SelPlatesNo - 1) As Long objOpenSTAAD.Geometry.getselectedplates SelPlates ''load case details LOADSTART = Cells(5, 4) LOADEND = Cells(5, 6) diff = LOADEND - LOADSTART diff = diff + 1 For count2 = 1 To SelPlatesNo For count1 = 0 To diff Cells(count2 * diff + count1 + 3, 2).Value = LOADSTART + count1 Cells(count2 * diff + count1 + 3, 1).Value = SelPlates(count2 - 1) lLoadCase = Cells(count2 * diff + count1, 2).Value staad.Output.getallplatecenterstressesandmoments SelPlates(count2), lLoadCase, dCenterStressesArray For count3 = 1 To 8 Cells(count2 * diff + count1, count3 + 2).Value = dCenterStressesArray(count3 - 1) Next Next Next End Sub
Hi Suro, this works great. Thanks for the share. The macro only works for the load cases, I have some load combinations as well along with the load case. Could you please let me know how to tweak the macro inorder to make it work for load combinations?
Hello Suro,
I wanted an excel VBA to find the plate corner stresses/moments from a group of plates from my STAAD pro. can you help me out with this?