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