Using OpenSTAAD in a simple VB.NET project

From the outset let me be clear, I am not a programmer.  I am sure many of you will be able to look at the code I share and suggest better ways of achieving the same effect as demonstrated in this project.  Please feel free to add your comments and experience to help others produce their own solutions.

However, saying that I hope you will be able to see the important points that I am trying to share and that are needed to produce your own VB.NET project.

Over the years, I have used OpenSTAAD in VBA in macros in STAAD.Pro and in Excel.  However there are some noticable differnces that need to be observed to successfully use OpenSTAAD in a VB.NET project.

I have created a simple dialog that displays the number and list of beams and load cases in the current STAAD.Pro model.

The project is attached with some comments to indicate the important things that need to be taken into consideration compared to a similar VBA or VB6 project, namely

1) When using Option Strict, (eqiuivalent to OPTION EXPLICIT in VBA/VB6), then late binding is not supported and thus it is not possible to access object members such as would be done with objSTAAD.Geometry.***.  Therefore we need to create new variables for these members.

2) Function calls need to be cast to the expected return type, e.g. myBeamCount = CInt(mySTAADGeometry.GetMemberCount)

3) The most important point is that the size of INTEGERS and LONGS have changed and thus where in VBA we would define a varriable as a LONG, in VB.NET, this should now be defined as an INTEGER.

4) Functions that expect arrays, need to have these first cast as OBJECTS, the object passed, and the results cast back to the original array type.

Feel free to add other sample projects or tips to help others.

Regards

Carlos

Test OpenSTAAD.zip
Anonymous
Parents
  • Hi i am trying to develop code for extracting utilization ratio in staad pro but i am facing little bit of problem while coding please suggest me your opinion               

      Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
    
    
    
            Dim appXL As Excel.Application
            Dim wbXl As Excel.Workbook
            Dim shXL As Excel.Worksheet
            Dim raXL As Excel.Range
            ' Start Excel and get Application object.
            appXL = CreateObject("Excel.Application")
            appXL.Visible = True
            wbXl = appXL.Workbooks.Add
            shXL = wbXl.ActiveSheet
    
    
    
    
            Dim objOpenSTAAD As Object
    
            Dim lBeamCnt As Integer
            Dim BeamNumberArray() As Integer
            Dim mem As Integer
            Dim pdRatio As Double
            Dim sBeamMaterialName As String
            Dim lBeamSectionName As String
            '' shXL.Range("A4:e10010").ClearContents()
            objOpenSTAAD = GetObject(, "StaadPro.OpenSTAAD")
            lBeamCnt = objOpenSTAAD.Geometry.GetMemberCount
    
            ReDim Preserve BeamNumberArray(0 To (lBeamCnt - 1))
            objOpenSTAAD.Geometry.GetBeamList(BeamNumberArray)
            For I = 1 To lBeamCnt
                objOpenSTAAD.Geometry.GetBeamList(BeamNumberArray)
                Dim X As Double
    
                shXL.Cells(I + 3, 1) = BeamNumberArray(I - 1)
                mem = shXL.Cells(I + 3, 1).Value
                objOpenSTAAD.Output.GetMemberSteelDesignRatio(mem, pdRatio)
                shXL.Cells(I + 3, 4) = pdRatio
                sBeamMaterialName = objOpenSTAAD.Property.GetBeamMaterialName(mem)
                lBeamSectionName = objOpenSTAAD.Property.GetBeamSectionName(mem)
                shXL.Cells(I + 3, 2) = sBeamMaterialName
                shXL.Cells(I + 3, 3) = lBeamSectionName
    
    
    
            Next I
    
        End Sub
    
    End Class

Comment
  • Hi i am trying to develop code for extracting utilization ratio in staad pro but i am facing little bit of problem while coding please suggest me your opinion               

      Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
    
    
    
            Dim appXL As Excel.Application
            Dim wbXl As Excel.Workbook
            Dim shXL As Excel.Worksheet
            Dim raXL As Excel.Range
            ' Start Excel and get Application object.
            appXL = CreateObject("Excel.Application")
            appXL.Visible = True
            wbXl = appXL.Workbooks.Add
            shXL = wbXl.ActiveSheet
    
    
    
    
            Dim objOpenSTAAD As Object
    
            Dim lBeamCnt As Integer
            Dim BeamNumberArray() As Integer
            Dim mem As Integer
            Dim pdRatio As Double
            Dim sBeamMaterialName As String
            Dim lBeamSectionName As String
            '' shXL.Range("A4:e10010").ClearContents()
            objOpenSTAAD = GetObject(, "StaadPro.OpenSTAAD")
            lBeamCnt = objOpenSTAAD.Geometry.GetMemberCount
    
            ReDim Preserve BeamNumberArray(0 To (lBeamCnt - 1))
            objOpenSTAAD.Geometry.GetBeamList(BeamNumberArray)
            For I = 1 To lBeamCnt
                objOpenSTAAD.Geometry.GetBeamList(BeamNumberArray)
                Dim X As Double
    
                shXL.Cells(I + 3, 1) = BeamNumberArray(I - 1)
                mem = shXL.Cells(I + 3, 1).Value
                objOpenSTAAD.Output.GetMemberSteelDesignRatio(mem, pdRatio)
                shXL.Cells(I + 3, 4) = pdRatio
                sBeamMaterialName = objOpenSTAAD.Property.GetBeamMaterialName(mem)
                lBeamSectionName = objOpenSTAAD.Property.GetBeamSectionName(mem)
                shXL.Cells(I + 3, 2) = sBeamMaterialName
                shXL.Cells(I + 3, 3) = lBeamSectionName
    
    
    
            Next I
    
        End Sub
    
    End Class

Children