structural connections, steel design software, steel connection design, design analysis software, Tekla, integrated, import export Tekla, Staad, Sap2000, integrated with Staad,
                                          Staad import, Sap2000 import, API, Staad Pro, Application Programming Interface

Expand SCS reach through powerful APIs

For commercial inquiries please write to
sales@steelconnectionstudio.com
For technical inquiries please write to
support@steelconnectionstudio.com
API examples HOMEPAGE
Import loads from Sap2000 Download code, form included
This example shows how to connect SCS to Sap2000 in order to automatically import into SCS the joint actions for some specific load cases. You need to have a licensed version of Sap2000 (it was made with version 14).
Actually now (SCS version 15 and later) SCS has built in the buttons to import from more recent Sap2000 version (16 and 17) but the example is left here as a possible tutorial for SCS APIs usage. It was tested with Visual Basic Express 2010.

Sap2000 steel connections design integration

Option Explicit On
Option Strict Off
'ADD SCS.exe (default location under ...Program Files (x86)\Steel Studio\SCS or equivalent) to your References. SCS.exe (no dll needed) is a .NET type reference. Set 'Copy Local' = True
'In some versions of Visual Studio it might be necessary to set x86 as a target reference to make SCS APIs work
'The macro was tested for Sap2000 version 14 in Microsoft Visual Basic 2010 Express (framework 4)
Imports mySCS
Imports SapModel
Imports Sap2000
Imports System.Math
Imports System.Runtime.InteropServices
Imports System.Runtime.InteropServices.ComTypes

Public Class Form2a
    Inherits System.Windows.Forms.Form
    Private scsObj As mySCS.frmShapedStart
    Private scsModuleGeneric As mySCS.frmFP1 'all modules inherit from type frmFP1 therefore this can point out to any form
    Private WorkingPath As String = IO.Directory.GetParent(IO.Directory.GetParent(Application.StartupPath).FullName.ToString).FullName.ToString & "\ExampleFiles\"
    Private booFirstTime As Boolean = True
    Private booPrimaryMemberIsaColumn As Boolean = False
    Private booBasePlateJoint As Boolean = False
    Private booBraceJoint As Boolean = False
    Private booSpliceJoint As Boolean = False
    Private formYsize As Integer
    Private tipHowToCreateNewSCSFile As String = "To create a new file use '*'." & vbCrLf & "Example: write *.em3 in the textbox and clicking the 'New' button a new em3 (moment connection) file will be launched."
    Public Sub New()
        ' This call is required by the Windows Form Designer.
        InitializeComponent()
        ' Add any initialization after the InitializeComponent() call.
        formYsize = Me.Size.Height
        Me.Size = New Point(324, formYsize)
        Me.TopMost = True
        btnFormOnTop_Click(btnFormOnTop, New System.EventArgs) 'comment this if you want topmost to true because this command will switch the above command

        ToolTip1.SetToolTip(txbSCSfileName, ToolTip1.GetToolTip(btnNewSCS))
    End Sub
    Private Sub btnSCSopenFile1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSCSopenFile.Click, btnNewSCS.Click
        CheckifSCSIsOpen()
        Dim fileName As String = txbSCSfileName.Text
        'if the file name is just an asterisk, a new file is created
        If (fileName.Length = 5 AndAlso fileName.Substring(0, 2) = "*.") Or (fileName.Length = 4 AndAlso fileName.Substring(0, 1) = ".") Then
            If CType(sender, Button).Name = btnSCSopenFile.Name Then
                MsgBox("a new file will be created")
            End If
            Dim extensionString As String = fileName.Substring(fileName.Length - 3, 3)
            scsObj.NewFileAndAssignGenericModuleObject(extensionString, scsModuleGeneric) 'open file directly then, adding the generic module reference will assign the new form to this object 
        Else
            If CType(sender, Button).Name = btnSCSopenFile.Name Then
                scsObj.OpenFileAndAssignGenericModuleObject(WorkingPath & txbSCSfileName.Text, scsModuleGeneric) 'open file directly then, adding the generic module reference will assign the new form to this object 
            Else
                MsgBox(tipHowToCreateNewSCSFile)
            End If
        End If
    End Sub
    Private SapObject As Sap2000.SapObject
    Private SapModel As cSapModel
    Private ret As Long
    Private booFormAlreadyOpen As Boolean = False
    Private JointData() As Sap2000JointData
    Private secframeList() As String
    Private jointList() As String
    'Private FrameElems() As FrameElement
    Private Sub btnOpenFile_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSap2000OpenFile.Click
        'create Sap2000 object
        SapObject = New Sap2000.SapObject
        'start Sap2000 application
        SapObject.ApplicationStart()
        Dim SapFile As New Sap2000.cFile
        ret = SapFile.OpenFile(WorkingPath & txbSapFileName.Text)
        'attach SapModel object to the current file running in the application
        SapModel = SapObject.SapModel
    End Sub
    Private Sub CheckifSapIsOpen()
        If SapModel Is Nothing Then 'if Sap is running already and the right file is open, the open file button click can be avoided and the SapModel object is assigned below
            SapObject = New Sap2000.SapObject
            SapModel = SapObject.SapModel
        End If
    End Sub
    Private Sub CheckifSCSIsOpen()
        If scsObj Is Nothing Then
            scsObj = New mySCS.frmShapedStart
            scsObj.ApplicationStart()
        End If
    End Sub
    Private Function IsBasePlateJoint() As Boolean
        Dim boo As Boolean = False
        Try
            Dim SCSfileExtension As String = txbSCSfileName.Text.Substring(txbSCSfileName.Text.Length - 4, 4)
            If SCSfileExtension.StartsWith(".") Then
                Select Case SCSfileExtension
                    Case Is = ".cb8"
                        Return True
                End Select
            End If
            Return boo
        Catch ex As Exception
            Return False
        End Try
    End Function
    Private Function IsBraceJoint() As Boolean
        Dim boo As Boolean = False
        Try
            Dim SCSfileExtension As String = txbSCSfileName.Text.Substring(txbSCSfileName.Text.Length - 4, 4)
            If SCSfileExtension.StartsWith(".") Then
                Select Case SCSfileExtension
                    Case Is = ".br9"
                        Return True
                End Select
            End If
            Return boo
        Catch ex As Exception
            Return False
        End Try
    End Function
    Private Function IsSpliceJoint() As Boolean
        Dim boo As Boolean = False
        Try
            Dim SCSfileExtension As String = txbSCSfileName.Text.Substring(txbSCSfileName.Text.Length - 4, 4)
            If SCSfileExtension.StartsWith(".") Then
                Select Case SCSfileExtension
                    Case Is = ".sp4"
                        Return True
                End Select
            End If
            Return boo
        Catch ex As Exception
            Return False
        End Try
    End Function
    Private Function IsPrimaryMemeberAColumn() As Boolean
        Dim boo As Boolean = False
        Dim msgtxt As String = "Select SCS file (it's needed to determine primary members) then re-load data"
        If txbSCSfileName.TextLength < 4 Then
            MsgBox(msgtxt)
        Else
            Dim SCSfileExtension As String = txbSCSfileName.Text.Substring(txbSCSfileName.Text.Length - 4, 4)
            If SCSfileExtension.StartsWith(".") Then
                Select Case SCSfileExtension
                    Case Is = ".fp1", ".xl1", ".qs5", ".em3", ".we1"
                        Return True
                End Select
            Else
                MsgBox(msgtxt)
            End If
        End If
        Return boo
    End Function
    Private Sub btnSap2000DoStuff_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSap2000DoStuff.Click
        CheckifSapIsOpen()
        lblSelJointsStrings.Text = Nothing
        lblSecMemberProperty.Text = Nothing
        cobPrimaryMember.Items.Clear()
        booPrimaryMemberIsaColumn = IsPrimaryMemeberAColumn()
        booBasePlateJoint = IsBasePlateJoint()
        booBraceJoint = IsBraceJoint()
        booSpliceJoint = IsSpliceJoint()

        If booBasePlateJoint Then
            btnPrimMembShow.Visible = False
            lblPrimaryMember.Visible = False
            cobPrimaryMember.Visible = False
        Else
            btnPrimMembShow.Visible = True
            lblPrimaryMember.Visible = True
            cobPrimaryMember.Visible = True
        End If

        MsgBox("Go to the open Sap model: select SECONDARY members AND JOINTS you want loads from THEN click OK", MsgBoxStyle.OkOnly)

        Dim a As Integer
        Dim b() As Int32
        Dim c() As String
        ret = SapModel.SelectObj.GetSelected(a, b, c)
        Dim strSelectedPoints As String = Nothing
        ReDim jointList(0)
        Dim NumberOfJoints As Integer = 0
        Dim NumberOfSecondaryMembers As Integer = 0
        For i = 0 To a - 1
            Select Case b(i) '1 stands for point selection, 2 for frames
                Case Is = 1
                    ReDim Preserve jointList(NumberOfJoints)
                    jointList(NumberOfJoints) = c(i)
                    NumberOfJoints += 1
                    strSelectedPoints += c(i) + ", "
                Case Is = 2
                    ReDim Preserve secframeList(NumberOfSecondaryMembers)
                    secframeList(NumberOfSecondaryMembers) = c(i)
                    NumberOfSecondaryMembers += 1
            End Select
        Next
        If NumberOfSecondaryMembers = 0 Then
            MsgBox("no secondary member selected, go to Sap and modify selection")
            btnSap2000DoStuff_Click(sender, e)
            Exit Sub
        End If
        If NumberOfJoints = 0 Then
            MsgBox("no joints selected, go to Sap and modify selection")
            btnSap2000DoStuff_Click(sender, e)
            Exit Sub
        End If

        lblSelJointsStrings.Text = strSelectedPoints

        'variables necessary for Sap API calls
        Dim JointArrayMaxIndex As Integer = Max(0, NumberOfJoints - 1)
        ReDim JointData(JointArrayMaxIndex)
        Dim NumberItems As Integer
        Dim ObjectType() As Integer
        Dim ObjectName() As String
        Dim PointNumber() As Integer
        Dim DataB_ObjName(JointArrayMaxIndex, 0) As String
        Dim DataB_PointNumber(JointArrayMaxIndex, 0) As String
        Dim DataB_PropertyName(JointArrayMaxIndex, 0) As String
        Dim maxExt As Integer = 0
        Dim PropName As String = Nothing
        Dim ObjType As Long
        Dim Var As Boolean
        Dim sVarRelStartLoc As Double
        Dim sVarTotalLength As Double
        Dim Members As New List(Of String)
        Dim Area As Double
        Dim as2 As Double
        Dim as3 As Double
        Dim Torsion As Double
        Dim I22 As Double
        Dim I33 As Double
        Dim S22 As Double
        Dim S33 As Double
        Dim Z22 As Double
        Dim Z33 As Double
        Dim R22 As Double
        Dim R33 As Double
        Dim nelm As Long
        Dim Elm() As String
        Dim RDI() As Double
        Dim RDJ() As Double
        Dim Point1 As String
        Dim Point2 As String
        Dim x As Double, y As Double, z As Double
        Dim x2 As Double, y2 As Double, z2 As Double

        ret = SapModel.FrameObj.GetElm(secframeList(0), nelm, Elm, RDI, RDJ)
        If Elm Is Nothing Then
            MsgBox("run analysis and then restart command")
            Exit Sub
        End If
        ret = SapModel.LineElm.GetProperty(Elm(0), PropName, ObjType, Var, sVarRelStartLoc, sVarTotalLength)
        If NumberOfSecondaryMembers > 1 Then
            Dim PropName2 As String
            For k = 1 To NumberOfSecondaryMembers - 1
                ret = SapModel.FrameObj.GetElm(secframeList(k), nelm, Elm, RDI, RDJ)
                ret = SapModel.LineElm.GetProperty(Elm(0), PropName2, ObjType, Var, sVarRelStartLoc, sVarTotalLength)
                If PropName2 <> PropName Then
                    MsgBox("secondary members must have the same section property, go to Sap and modify selection")
                    btnSap2000DoStuff_Click(sender, e)
                    Exit Sub
                End If
            Next
        End If
        lblSecMemberProperty.Text = PropName

        For k = 0 To JointArrayMaxIndex
            ret = SapModel.PointElm.GetConnectivity(jointList(k), NumberItems, ObjectType, ObjectName, PointNumber)
            Dim maxExtTemp As Integer = NumberItems - 1
            Dim listItemstoExclude As New List(Of Integer)
            For u = 0 To maxExtTemp
                If ObjectType(u) <> 2 Then
                    listItemstoExclude.Add(u)
                End If
            Next
            maxExtTemp += -listItemstoExclude.Count
            If maxExtTemp < 0 Then
                MsgBox("no useful joints selected")
                Exit Sub
            End If
            JointData(k) = New Sap2000JointData(maxExtTemp + 1)
            JointData(k).PrimaryMemberIsaColumn = booPrimaryMemberIsaColumn
            JointData(k).BasePlateJoint = booBasePlateJoint
            JointData(k).BraceJoint = booBraceJoint
            JointData(k).Label = jointList(k)
            If maxExtTemp > maxExt Then
                maxExt = maxExtTemp
                ReDim Preserve DataB_ObjName(JointArrayMaxIndex, maxExt)
                ReDim Preserve DataB_PointNumber(JointArrayMaxIndex, maxExt)
                ReDim Preserve DataB_PropertyName(JointArrayMaxIndex, maxExt)
            End If
            Dim q As Integer
            Dim counting As Integer = 0
            For qq = 0 To NumberItems - 1
                If listItemstoExclude.Contains(qq) Then
                    counting += 1
                Else
                    q = qq - counting
                    DataB_ObjName(k, q) = ObjectName(q)
                    ret = SapModel.LineElm.GetProperty(DataB_ObjName(k, q), PropName, ObjType, Var, sVarRelStartLoc, sVarTotalLength)
                    ret = SapModel.PropFrame.GetSectProps(PropName, Area, as2, as3, Torsion, I22, I33, S22, S33, Z22, Z33, R22, R33)
                    DataB_PropertyName(k, q) = PropName
                    JointData(k).GuessedPrimaryMember_property_OverWrite = False
                    JointData(k).PropertyName(q) = PropName
                    JointData(k).ObjName(q) = ObjectName(q) 'this is the analysis label, example 36-2
                    JointData(k).PointNumber(q) = PointNumber(q)
                    JointData(k).PropertyRefValue(q) = S33
                    JointData(k).GuessedSecondaryMember_property = PropName
                    Members.Add(PropName)
                    JointData(k).GetObjNameRoot(q) 'this is the model label, example 36
                    ret = SapModel.LineElm.GetPoints(ObjectName(q), Point1, Point2)
                    If Point1 = jointList(k) Then
                        JointData(k).ObjNode(q) = 0
                    Else
                        JointData(k).ObjNode(q) = 1
                    End If
                    ReDim Preserve JointData(k).FrameElements(q)
                    ret = SapModel.FrameObj.GetPoints(JointData(k).ObjectNameRoot(q), Point1, Point2)
                    ret = SapModel.PointObj.GetCoordCartesian(Point1, x, y, z)
                    ret = SapModel.PointObj.GetCoordCartesian(Point2, x2, y2, z2)
                    Dim co1() As Double = {x, y, z}
                    Dim co2() As Double = {x2, y2, z2}
                    JointData(k).FrameElements(q) = New FrameElement(JointData(k).ObjectNameRoot(q), co1, co2) 'this is the model label, example 36
                End If
            Next
            JointData(k).GuessPrimaryMembersAndAssignSecMembers(secframeList)
        Next

        If JointArrayMaxIndex > 0 Then
            For uu = 1 To JointArrayMaxIndex
                For jjjj = 0 To uu - 1
                    If JointData(jjjj).GuessedPrimaryMember_property <> JointData(uu).GuessedPrimaryMember_property Then
                        MsgBox("problem with primary members, it seems members with labels " & JointData(jjjj).GuessedPrimaryMember_Name & " and " & JointData(uu).GuessedPrimaryMember_Name & " have different properties, please check")
                        Exit For
                    End If
                Next
            Next
        End If

        If booFirstTime Then
            Me.Size = New Point(924, formYsize)
            cobFilter.SelectedIndex = 0
            lblWarning.Text = ""
        End If

        Dim MembersDistinctList As New List(Of String)
        MembersDistinctList = FindDistinctValues(Members)
        For r = 0 To MembersDistinctList.Count - 1
            cobPrimaryMember.Items.Add(MembersDistinctList.Item(r))
        Next
        AssignComboBoxValue(cobPrimaryMember, JointData(0).GuessedPrimaryMember_property)

        'If booFirstTime Then '141127 revision: it's better to reload everytime so that, if file is changed, the correct load combos are loaded
        MemorizeListBoxSelection()
        ListBox1.Items.Clear()
        Dim NumberNames As Long
        Dim MyName() As String
        ret = SapModel.RespCombo.GetNameList(NumberNames, MyName)
        For qq = 0 To NumberNames - 1
            ListBox1.Items.Add(MyName(qq))
        Next
        If LoadCasesSelected.Count > 0 Then '141127 revision to reselect previous load cases after data are reloaded
            For ww = 0 To LoadCasesSelected.Count - 1
                For i = 0 To ListBox1.Items.Count - 1
                    If ListBox1.Items(i).ToString = LoadCasesSelected(ww) Then
                        ListBox1.SetSelected(i, True)
                        Exit For
                    End If
                Next
            Next
        End If
        booFirstTime = False
        'End If
    End Sub
    Public Sub ExportResults(ByVal LoadCases As String())
        'ret = SapModel.Analyze.RunAnalysis
        'clear all case and combo output selections
        If LoadCases.Count = 0 Then
            MsgBox("select load cases")
            Exit Sub
        End If
        Dim MyUnits As SapModel.eUnits
        MyUnits = SapModel.GetPresentUnits
        Dim SapUnitsString As String = MyUnits.ToString
        Dim SapForce As String
        Dim firstStop As Integer = SapUnitsString.IndexOf("_")
        SapForce = SapUnitsString.Substring(0, firstStop)
        Dim multiplierForce As Double = 1
        Dim multiplierMoment As Double = 1
        Dim roundingfiguresForce As Integer = 2
        Dim roundingfiguresMoment As Integer = 2
        Dim secondStop As Integer = SapUnitsString.Substring(firstStop + 1, SapUnitsString.Length - firstStop - 1).IndexOf("_")
        Dim SapLength As String = SapUnitsString.Substring(firstStop + 1, secondStop)
        Try
            ret = SapModel.CoordSys.SetCoordSys("GLOBAL", 0, 0, 0, 0, 0, 0)
        Catch ex As Exception
            MsgBox("ERROR SETTING COORD SYS")
        End Try
        ret = SapModel.Results.Setup.DeselectAllCasesAndCombosForOutput
        'set case and combo output selections
        For Each value In LoadCases
            ret = SapModel.Results.Setup.SetComboSelectedForOutput(value)
        Next

        Dim NumberResults As Long
        Dim Obj() As String
        Dim Elm() As String
        'Dim PointElm() As String
        Dim LoadCase() As String
        Dim StepType() As String
        Dim StepNum() As Double
        Dim F1() As Double
        Dim F2() As Double
        Dim F3() As Double
        Dim JM1() As Double
        Dim JM2() As Double
        Dim JM3() As Double
        Dim F1ta(), F1tb(), F1tc() As Double
        Dim F2ta(), F2tb(), F2tc() As Double
        Dim F3ta(), F3tb(), F3tc() As Double
        Dim JM1ta(), JM1tb(), JM1tc() As Double
        Dim JM2ta(), JM2tb(), JM2tc() As Double
        Dim JM3ta(), JM3tb(), JM3tc() As Double
        Dim M2() As Double
        Dim M3() As Double
        Dim FrameLabel As String
        Dim ObjSta() As Double
        Dim ElmSta() As Double
        Dim P() As Double
        Dim V2() As Double
        Dim V3() As Double
        Dim T() As Double
        Dim LCname() As String
        Dim Pf(), V2f(), V3f(), M2f(), M3f(), Tf() As Double
        Dim Pftemp(), V2ftemp(), V3ftemp(), M2ftemp(), M3ftemp(), Tftemp() As Double
        Dim totalCasestoExport As Integer
        For x = 0 To JointData.Length - 1
            If booBasePlateJoint Then
                Dim JointLabel As String
                Try
                    JointLabel = JointData(x).Label
                Catch ex As Exception
                    MsgBox("run analysis and then restart command")
                    Exit Sub
                End Try
                ret = SapModel.Results.JointReact(JointLabel, eItemTypeElm.Element, NumberResults, Obj, Elm, LoadCase, StepType, StepNum, F1, F2, F3, JM1, JM2, JM3)
                If Elm Is Nothing Then
                    MsgBox("run analysis and then restart command")
                    Exit Sub
                End If
                Dim a As Double, b As Double, c As Double, Ang As Double
                'to adjust if local axes of joint are rotated. 
                ret = SapModel.PointElm.GetLocalAxes(JointLabel, a, b, c)
                a = a / 180 * PI
                b = b / 180 * PI
                c = c / 180 * PI
                'to adjust if local axis of member is rotated
                'To adjust if some 'advanced' features are used, like rotation for points or planes, MANUAL correction is needed, the macro doesn't get correct values automatically (it seems there are no SAP API commands to automate this)
                ret = SapModel.LineElm.GetLocalAxes(JointData(x).GuessedSecondaryMember_Name(0), Ang)
                Ang = Ang / 180 * PI
                totalCasestoExport = NumberResults
                ReDim Pf(totalCasestoExport - 1)
                ReDim V2f(totalCasestoExport - 1)
                ReDim V3f(totalCasestoExport - 1)
                ReDim M2f(totalCasestoExport - 1)
                ReDim M3f(totalCasestoExport - 1)
                ReDim Tf(totalCasestoExport - 1)
                ReDim LCname(totalCasestoExport - 1)
                ReDim Pftemp(totalCasestoExport - 1)
                ReDim V2ftemp(totalCasestoExport - 1)
                ReDim V3ftemp(totalCasestoExport - 1)
                ReDim M2ftemp(totalCasestoExport - 1)
                ReDim M3ftemp(totalCasestoExport - 1)
                ReDim Tftemp(totalCasestoExport - 1)
                ReDim F1ta(totalCasestoExport - 1)
                ReDim F2ta(totalCasestoExport - 1)
                ReDim F3ta(totalCasestoExport - 1)
                ReDim F1tb(totalCasestoExport - 1)
                ReDim F2tb(totalCasestoExport - 1)
                ReDim F3tb(totalCasestoExport - 1)
                ReDim F1tc(totalCasestoExport - 1)
                ReDim F2tc(totalCasestoExport - 1)
                ReDim F3tc(totalCasestoExport - 1)
                ReDim JM1ta(totalCasestoExport - 1)
                ReDim JM2ta(totalCasestoExport - 1)
                ReDim JM3ta(totalCasestoExport - 1)
                ReDim JM1tb(totalCasestoExport - 1)
                ReDim JM2tb(totalCasestoExport - 1)
                ReDim JM3tb(totalCasestoExport - 1)
                ReDim JM1tc(totalCasestoExport - 1)
                ReDim JM2tc(totalCasestoExport - 1)
                ReDim JM3tc(totalCasestoExport - 1)
                For w = 0 To totalCasestoExport - 1
                    F1tc(w) = F1(w)
                    F2tc(w) = F2(w) * Cos(c) - F3(w) * Sin(c)
                    F3tc(w) = F2(w) * Sin(c) + F3(w) * Cos(c)
                    F1tb(w) = F3tc(w) * Sin(b) + F1tc(w) * Cos(b)
                    F2tb(w) = F2tc(w)
                    F3tb(w) = F3tc(w) * Cos(b) - F1tc(w) * Sin(b)
                    F1ta(w) = F1tb(w) * Cos(a) - F2tb(w) * Sin(a)
                    F2ta(w) = F1tb(w) * Sin(a) + F2tb(w) * Cos(a)
                    F3ta(w) = F3tb(w)
                    JM1tc(w) = JM1(w)
                    JM2tc(w) = JM2(w) * Cos(c) - JM3(w) * Sin(c)
                    JM3tc(w) = JM2(w) * Sin(c) + JM3(w) * Cos(c)
                    JM1tb(w) = JM3tc(w) * Sin(b) + JM1tc(w) * Cos(b)
                    JM2tb(w) = JM2tc(w)
                    JM3tb(w) = JM3tc(w) * Cos(b) - JM1tc(w) * Sin(b)
                    JM1ta(w) = JM1tb(w) * Cos(a) - JM2tb(w) * Sin(a)
                    JM2ta(w) = JM1tb(w) * Sin(a) + JM2tb(w) * Cos(a)
                    JM3ta(w) = JM3tb(w)

                    Select Case JointData(x).FrameElements(JointData(x).GuessedSecondaryMember_index(0)).MainDirection_0x_1y_2z_3xyPlane_4xzplane_5yzplane_6xyz
                        Case Is = 0
                            Pftemp(w) = -F1ta(w)
                            V2ftemp(w) = F2ta(w) * Cos(Ang) - F3ta(w) * Sin(Ang)
                            V3ftemp(w) = F2ta(w) * Sin(Ang) + F3ta(w) * Cos(Ang)
                            Tftemp(w) = JM1ta(w)
                            M2ftemp(w) = JM2ta(w) * Cos(Ang) - JM3ta(w) * Sin(Ang)
                            M3ftemp(w) = JM2ta(w) * Sin(Ang) + JM3ta(w) * Cos(Ang)
                        Case Is = 1
                            Pftemp(w) = -F2ta(w)
                            V2ftemp(w) = F3ta(w) * Cos(Ang) - F1ta(w) * Sin(Ang)
                            V3ftemp(w) = F3ta(w) * Sin(Ang) + F1ta(w) * Cos(Ang)
                            Tftemp(w) = JM2ta(w)
                            M2ftemp(w) = JM3ta(w) * Cos(Ang) - JM1ta(w) * Sin(Ang)
                            M3ftemp(w) = JM3ta(w) * Sin(Ang) + JM1ta(w) * Cos(Ang)
                        Case Is = 2
                            Pftemp(w) = -F3ta(w)
                            V2ftemp(w) = F1ta(w) * Cos(Ang) - F2ta(w) * Sin(Ang)
                            V3ftemp(w) = F1ta(w) * Sin(Ang) + F2ta(w) * Cos(Ang)
                            Tftemp(w) = JM3ta(w)
                            M2ftemp(w) = JM1ta(w) * Cos(Ang) - JM2ta(w) * Sin(Ang)
                            M3ftemp(w) = JM1ta(w) * Sin(Ang) + JM2ta(w) * Cos(Ang)
                        Case Else
                            If w = 0 Then MsgBox("check how to distribute correctly loads along member axes")
                            'formulas belew are not ok, just general reference, MANUAL modification necessary
                            Pftemp(w) = -F3ta(w)
                            V2ftemp(w) = F1ta(w)
                            V3ftemp(w) = F2ta(w)
                            Tftemp(w) = JM3ta(w)
                            M2ftemp(w) = JM1ta(w)
                            M3ftemp(w) = JM2ta(w)
                    End Select
                    If StepType(w) = Nothing Then
                        LCname(w) = LoadCase(w)
                    Else
                        LCname(w) = LoadCase(w) & ", " & StepType(w)
                    End If
                    Pf(w) = CheckMostStressingValue(Pf(w), Pftemp(w))
                    V2f(w) = CheckMostStressingValue(V2f(w), V2ftemp(w))
                    V3f(w) = CheckMostStressingValue(V3f(w), V3ftemp(w))
                    M2f(w) = CheckMostStressingValue(M2f(w), M2ftemp(w))
                    M3f(w) = CheckMostStressingValue(M3f(w), M3ftemp(w))
                    Tf(w) = CheckMostStressingValue(Tf(w), Tftemp(w))
                Next

            Else
                For xx = 0 To JointData(x).GuessedSecondaryMember_Name.Length - 1
                    FrameLabel = JointData(x).GuessedSecondaryMember_Name(xx) 'example 36-2
                    ret = SapModel.Results.FrameForce(FrameLabel, eItemTypeElm.Element, NumberResults, Obj, ObjSta, Elm, ElmSta, LoadCase, StepType, StepNum, P, V2, V3, T, M2, M3)
                    Dim numberofStations As Integer = 1
                    Dim InitialVal As Double = ObjSta(0)
                    For qq = 1 To ObjSta.Count - 1
                        If ObjSta(qq) = InitialVal Then Exit For
                        numberofStations += 1
                    Next
                    Dim Delta As Integer = 0
                    If JointData(x).ObjNode(xx) = 1 Then Delta = numberofStations - 1
                    Dim w As Integer = 0
                    Dim LC As String = Nothing
                    If x = 0 And xx = 0 Then
                        totalCasestoExport = NumberResults / numberofStations
                        ReDim Pf(totalCasestoExport - 1)
                        ReDim V2f(totalCasestoExport - 1)
                        ReDim V3f(totalCasestoExport - 1)
                        ReDim M2f(totalCasestoExport - 1)
                        ReDim M3f(totalCasestoExport - 1)
                        ReDim Tf(totalCasestoExport - 1)
                        ReDim LCname(totalCasestoExport - 1)
                    End If
                    ReDim Pftemp(totalCasestoExport - 1)
                    ReDim V2ftemp(totalCasestoExport - 1)
                    ReDim V3ftemp(totalCasestoExport - 1)
                    ReDim M2ftemp(totalCasestoExport - 1)
                    ReDim M3ftemp(totalCasestoExport - 1)
                    ReDim Tftemp(totalCasestoExport - 1)
                    Dim refIndex As Integer
                    For w = 0 To totalCasestoExport - 1
                        refIndex = Delta + w * numberofStations
                        'note that in sap2000 P positive means tension, P negative means compression, same as SCS
                        Pftemp(w) = P(refIndex)
                        V2ftemp(w) = V2(refIndex)
                        V3ftemp(w) = V3(refIndex)
                        M2ftemp(w) = M2(refIndex)
                        M3ftemp(w) = M3(refIndex)
                        Tftemp(w) = T(refIndex)
                        If StepType(refIndex) = Nothing Then
                            LCname(w) = LoadCase(refIndex)
                        Else
                            LCname(w) = LoadCase(refIndex) & ", " & StepType(refIndex)
                        End If
                        Pf(w) = CheckMostStressingValue(Pf(w), Pftemp(w))
                        V2f(w) = CheckMostStressingValue(V2f(w), V2ftemp(w))
                        V3f(w) = CheckMostStressingValue(V3f(w), V3ftemp(w))
                        M2f(w) = CheckMostStressingValue(M2f(w), M2ftemp(w))
                        M3f(w) = CheckMostStressingValue(M3f(w), M3ftemp(w))
                        Tf(w) = CheckMostStressingValue(Tf(w), Tftemp(w))
                    Next
                Next
            End If
        Next

        If scsModuleGeneric Is Nothing Then
            btnSCSopenFile1_Click(btnSCSopenFile, New System.EventArgs)
        End If
        Try
            Dim SecMemberName As String = ChangeNameForHE(lblSecMemberProperty.Text)
            Dim PrimMemberName As String = ChangeNameForHE(cobPrimaryMember.SelectedItem.ToString)
            scsModuleGeneric.DataPage_Members.SecondaryMemberSection = SecMemberName
            If booBasePlateJoint = False And booSpliceJoint = False Then scsModuleGeneric.DataPage_Members.PrimaryMemberSection = PrimMemberName
            Select Case SapForce
                Case Is = "lb"
                    scsModuleGeneric.FormUnits.ForceUnit = "lbf"
                    roundingfiguresForce = 0
                    Select Case SapLength
                        Case Is = "in"
                            scsModuleGeneric.FormUnits.MomentUnit = "lbf*in"
                            roundingfiguresMoment = 0
                        Case Is = "ft"
                            scsModuleGeneric.FormUnits.MomentUnit = "lbf*ft"
                            roundingfiguresMoment = 2
                    End Select
                Case Is = "Kip", "kip"
                    scsModuleGeneric.FormUnits.ForceUnit = "kips"
                    roundingfiguresForce = 2
                    Select Case SapLength
                        Case Is = "in"
                            scsModuleGeneric.FormUnits.MomentUnit = "kips*in"
                            roundingfiguresMoment = 0
                        Case Is = "ft"
                            scsModuleGeneric.FormUnits.MomentUnit = "kips*ft"
                            roundingfiguresMoment = 2
                    End Select
                Case Is = "KN", "kN"
                    scsModuleGeneric.FormUnits.ForceUnit = "kN"
                    roundingfiguresForce = 2
                    Select Case SapLength
                        Case Is = "m"
                            scsModuleGeneric.FormUnits.MomentUnit = "kN*m"
                            roundingfiguresMoment = 2
                        Case Is = "mm"
                            scsModuleGeneric.FormUnits.MomentUnit = "kN*mm"
                            roundingfiguresMoment = 0
                        Case Is = "cm"
                            scsModuleGeneric.FormUnits.MomentUnit = "kN*mm"
                            roundingfiguresMoment = 0
                            multiplierMoment = 10
                    End Select
                Case Is = "N"
                    scsModuleGeneric.FormUnits.ForceUnit = "N"
                    roundingfiguresForce = 0
                    Select Case SapLength
                        Case Is = "m"
                            scsModuleGeneric.FormUnits.MomentUnit = "N*m"
                            roundingfiguresMoment = 0
                        Case Is = "mm"
                            scsModuleGeneric.FormUnits.MomentUnit = "N*mm"
                            roundingfiguresMoment = 0
                        Case Is = "cm"
                            scsModuleGeneric.FormUnits.MomentUnit = "N*mm"
                            roundingfiguresMoment = 0
                            multiplierMoment = 10
                    End Select
                Case Is = "Tonf", "Ton", "ton", "tons"
                    scsModuleGeneric.FormUnits.ForceUnit = "kN"
                    roundingfiguresForce = 2
                    multiplierForce = 10
                    Select Case SapLength
                        Case Is = "m"
                            scsModuleGeneric.FormUnits.MomentUnit = "kN*m"
                            roundingfiguresMoment = 2
                            multiplierMoment = 10
                        Case Is = "mm"
                            scsModuleGeneric.FormUnits.MomentUnit = "kN*mm"
                            roundingfiguresMoment = 0
                            multiplierMoment = 10
                        Case Is = "cm"
                            scsModuleGeneric.FormUnits.MomentUnit = "kN*mm"
                            roundingfiguresMoment = 0
                            multiplierMoment = 100
                    End Select
                Case Is = "Kgf", "kgf"
                    scsModuleGeneric.FormUnits.ForceUnit = "kg"
                    roundingfiguresForce = 0
                    Select Case SapLength
                        Case Is = "m"
                            scsModuleGeneric.FormUnits.MomentUnit = "daN*m"
                            roundingfiguresMoment = 1
                            multiplierMoment = 0.981
                        Case Is = "mm"
                            scsModuleGeneric.FormUnits.MomentUnit = "N*mm"
                            roundingfiguresMoment = 0
                            multiplierMoment = 9.81
                        Case Is = "cm"
                            scsModuleGeneric.FormUnits.MomentUnit = "kg*cm"
                            roundingfiguresMoment = 0
                            multiplierMoment = 1
                    End Select
            End Select
            For w = 0 To totalCasestoExport - 1
                If w > 9 Then
                    MsgBox("Results are more than 10 arrays and import is stopped to 10")
                    Exit For
                End If
                scsModuleGeneric.DataPage_Loads.AxialForce(w) = Round(Pf(w) * multiplierForce, roundingfiguresForce).ToString
                scsModuleGeneric.DataPage_Loads.ShearForceMajorAxis(w) = Round(V2f(w) * multiplierForce, roundingfiguresForce).ToString
                scsModuleGeneric.DataPage_Loads.ShearForceMinorAxis(w) = Round(V3f(w) * multiplierForce, roundingfiguresForce).ToString
                scsModuleGeneric.DataPage_Loads.MomentMajorAxis(w) = Round(M3f(w) * multiplierMoment, roundingfiguresMoment).ToString
                'CAREFUL, MOMENT WEAK AXIS AND TORSION ARE NOT CALCULATED IN SOME SCS MODULES, MAKE SURE YOUR RESTRAINTS IN THE MODEL TAKE THIS INTO CONSIDERATION (hinges where necessary for pin type connections)
                If scsModuleGeneric.DataPage_Loads.IsLoadApplicable(claDataPage_Loads.LoadType.MomentMinorAxis) Then scsModuleGeneric.DataPage_Loads.MomentMinorAxis(w) = (Round(M2f(w) * multiplierMoment, roundingfiguresMoment)).ToString
                If scsModuleGeneric.DataPage_Loads.IsLoadApplicable(claDataPage_Loads.LoadType.Torsion) Then scsModuleGeneric.DataPage_Loads.Torsion(w) = (Round(Tf(w) * multiplierMoment, roundingfiguresMoment)).ToString
                scsModuleGeneric.DataPage_Loads.CaseName(w) = LCname(w)
            Next
            MsgBox("done")
        Catch ex As Exception
            MsgBox("Error in exporting members")
        End Try
    End Sub
    Private Function ChangeNameForHE(ByVal strR As String) As String
        If strR.StartsWith("HE") Then
            Dim NameMovingtheLetterToFront As String
            NameMovingtheLetterToFront = strR.Substring(0, 2) & strR.Substring(strR.Length - 1, 1) & strR.Substring(2, strR.Length - 3)
            Return NameMovingtheLetterToFront
        Else
            Return strR
        End If
    End Function
    Private Function CheckMostStressingValue(ByVal vl1 As Double, ByVal vl2 As Double) As Double
        If Abs(vl1) > Abs(vl2) Then
            Return vl1
        Else
            Return vl2
        End If
    End Function
    Public Sub AssignComboBoxValue(ByRef cob As ComboBox, ByVal stringa As String)
        For i = 0 To cob.Items.Count - 1
            If cob.Items(i).ToString = stringa Then
                cob.SelectedIndex = i
                Exit For
            End If
        Next
    End Sub
    Public Function FindDistinctValues(ByVal ListaStart As List(Of String)) As List(Of String)
        Dim itemsToRemove As New List(Of Integer)
        For j = 1 To ListaStart.Count - 1
            For jj = 0 To j - 1
                If ListaStart.Item(j) = ListaStart.Item(jj) Then
                    itemsToRemove.Add(j)
                    Exit For
                End If
            Next
        Next
        If itemsToRemove.Count > 0 Then
            For i = itemsToRemove.Count - 1 To 0 Step -1
                ListaStart.RemoveAt(itemsToRemove.Item(i))
            Next
        End If
        Return ListaStart
    End Function
    Private Sub ExitButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnExitSap.Click
        SapObject.ApplicationExit(False)
        SapModel = Nothing
        SapObject = Nothing
    End Sub
    Public Sub ShowMembers(ByVal _1primary_2secondary As Integer)
        If _1primary_2secondary = 1 Or _1primary_2secondary = 2 Then
            Dim target As String
            CheckifSapIsOpen()
            If JointData IsNot Nothing Then
                ret = SapModel.SelectObj.ClearSelection
                For j = 0 To jointList.Count - 1
                    ret = SapModel.PointObj.SetSelected(jointList(j).ToString, True)
                Next
                For j = 0 To JointData.Count - 1
                    For jj = 0 To JointData(j).ObjectCount - 1
                        If _1primary_2secondary = 1 Then
                            target = JointData(j).GuessedPrimaryMember_property
                        Else
                            target = JointData(j).GuessedSecondaryMember_property
                        End If
                        If JointData(j).PropertyName(jj) = target Then
                            ret = SapModel.FrameObj.SetSelected(JointData(j).ObjectNameRoot(jj), True)
                        End If
                    Next
                Next
                ret = SapModel.View.RefreshView
            End If
        End If
    End Sub
    Private strWarning As String = "You cannot choose more than 10 cases"
    Private Sub btnSecMembShow_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSecMembShow.Click
        ShowMembers(2)
    End Sub
    Private Sub btnPrimMembShow_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnPrimMembShow.Click
        ShowMembers(1)
    End Sub
    Private Sub cobPrimaryMember_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cobPrimaryMember.SelectedIndexChanged
        For Each item In JointData
            item.GuessedPrimaryMember_property_OverWrite = True
            item.GuessedPrimaryMember_property = cobPrimaryMember.SelectedItem
        Next
    End Sub
    Private LoadCasesSelected As String()
    Private Sub btnExportToSCS_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnExportToSCS.Click
        MemorizeListBoxSelection()
        ExportResults(LoadCasesSelected)
        Personalization()
    End Sub
    Private Sub Personalization()
        scsModuleGeneric.OtherControls.YourComments = "Output from joints " & lblSelJointsStrings.Text
    End Sub
    Private Sub MemorizeListBoxSelection()
        Dim value As ListBox.SelectedObjectCollection
        value = ListBox1.SelectedItems
        Dim totalnumber As Integer = value.Count
        If totalnumber > 10 Then
            lblWarning.Text = strWarning & ", only first 10 cases will be exported"
        Else
            lblWarning.Text = ""
        End If
        ReDim LoadCasesSelected(totalnumber - 1)
        For i = 0 To Min(10, totalnumber - 1)
            LoadCasesSelected(i) = value(i).ToString
        Next
    End Sub
    Private Sub btnFilter_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnFilter.Click
        Dim stringToLookFor As String = txbFilter.Text
        If chbFilter.Checked = False Then ListBox1.ClearSelected()
        Dim booIgnoreCase As Boolean = Not chbCaseSensitive.Checked
        Dim coun As Integer = 0
        Dim strComp As System.StringComparison = StringComparison.CurrentCultureIgnoreCase
        If chbCaseSensitive.Checked Then strComp = StringComparison.CurrentCulture
        For i = 0 To ListBox1.Items.Count - 1
            Select Case cobFilter.SelectedIndex
                Case Is = 0
                    If ListBox1.Items(i).ToString.StartsWith(stringToLookFor, booIgnoreCase, Nothing) Then
                        ListBox1.SetSelected(i, True)
                        coun += 1
                    End If
                Case Is = 1
                    If ListBox1.Items(i).ToString.IndexOf(stringToLookFor, 0, strComp) > -1 Then
                        ListBox1.SetSelected(i, True)
                        coun += 1
                    End If
            End Select
        Next
        If coun > 10 Then
            lblWarning.Text = strWarning
        Else
            lblWarning.Text = ""
        End If
    End Sub
    Private Sub btnExitSCS_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnExitSCS.Click
        scsModuleGeneric.Close()
        scsModuleGeneric = Nothing
    End Sub
    Private Sub btnFormOnTop_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnFormOnTop.Click
        If Me.TopMost Then
            Me.TopMost = False
            btnFormOnTop.Text = "Keep form on top of others"
        Else
            Me.TopMost = True
            btnFormOnTop.Text = "Don't keep form on top of others"
        End If
    End Sub
    Private Sub btnFindSimilar_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnFindSimilar.Click
        lblVisualCheck.Visible = True
        Dim NumberNames As Long
        Dim MyName() As String
        Dim NumberItems As Integer
        Dim ObjectType() As Integer
        Dim ObjectName() As String
        Dim PointNumber() As Integer
        Dim PropName As String = Nothing
        Dim ObjType As Long
        Dim Var As Boolean
        Dim sVarRelStartLoc As Double
        Dim sVarTotalLength As Double
        Dim SecProp As String = lblSecMemberProperty.Text
        Dim PrimProp As String = cobPrimaryMember.SelectedItem.ToString
        Dim booSamePropertyForPrimAndSec As Boolean = False
        Dim booMessageSamePropDisplayed As Boolean = False
        If SecProp = PrimProp Then booSamePropertyForPrimAndSec = True
        ret = SapModel.PointElm.GetNameList(NumberNames, MyName)
        Dim boook(1) As Boolean
        Dim Value(5) As Boolean
        For Each joint In MyName
            boook(0) = False
            boook(1) = False
            Dim SamePropArrayLength As Integer = 0
            ret = SapModel.PointElm.GetConnectivity(joint, NumberItems, ObjectType, ObjectName, PointNumber)
            Dim secIndex() As Integer
            Dim secIndexLength As Integer = 0
            For u = 0 To NumberItems - 1
                If ObjectType(u) = 2 Then
                    ret = SapModel.LineElm.GetProperty(ObjectName(u), PropName, ObjType, Var, sVarRelStartLoc, sVarTotalLength)
                    If booBasePlateJoint = False Then
                        If PropName = PrimProp Then boook(0) = True
                    Else
                        ret = SapModel.PointElm.GetRestraint(joint, Value)
                        If ret = 0 Then
                            For yy = 0 To 5
                                If Value(yy) = True Then
                                    boook(0) = True
                                End If
                            Next
                        End If
                    End If
                    If PropName = SecProp Then
                        boook(1) = True
                        ReDim Preserve secIndex(secIndexLength)
                        secIndex(secIndexLength) = u
                        secIndexLength += 1
                    End If
                End If
            Next
            Dim booGoMakeSelection As Boolean = False
            If boook(0) = True And boook(1) = True Then
                If booSamePropertyForPrimAndSec = False Then
                    booGoMakeSelection = True
                Else
                    If booSpliceJoint Then
                        If secIndexLength = 2 Then
                            booGoMakeSelection = True
                        End If
                    Else
                        If secIndexLength >= 3 Then
                            booGoMakeSelection = True
                        End If
                    End If
                End If
                If booGoMakeSelection Then
                    If booSamePropertyForPrimAndSec And booSpliceJoint = False Then
                        If booMessageSamePropDisplayed = False Then
                            MsgBox("primary and secondary members have the same property " & PropName & _
                                   " so the macro cannot understand which members are secondary and which primary." & _
                                   " Right now all members have been selected therefore manually unselect primary members")
                            booMessageSamePropDisplayed = True
                        End If
                    End If
                    For i = 0 To secIndexLength - 1
                        ret = SapModel.PointObj.SetSelected(joint.ToString, True)
                        Dim objnameroot As String = ObjectName(secIndex(i))
                        Try
                            objnameroot = objnameroot.Substring(0, objnameroot.LastIndexOf("-"))
                        Catch ex As Exception
                        End Try
                        ret = SapModel.FrameObj.SetSelected(objnameroot, True)
                    Next
                End If
            End If
        Next
        ret = SapModel.View.RefreshView
    End Sub
    Dim scsModuleGeneric2 As mySCS.frmFP1 'all modules inherit from type frmFP1 therefore this can point out to any form
    Private Sub btnPath_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnPath.Click
        OpenFileDialog1.Title = "choose SCS file to open"
        'OpenFileDialog1.Filter = strDocDialog
        If OpenFileDialog1.ShowDialog() = Windows.Forms.DialogResult.Cancel Then Exit Sub 'gaetano
        Dim sFilePathOpen As String
        sFilePathOpen = OpenFileDialog1.FileName
        If sFilePathOpen = Nothing Then Exit Sub
        If System.IO.File.Exists(sFilePathOpen) = False Then Exit Sub
        Dim exteN As String = sFilePathOpen.Substring(sFilePathOpen.Length - 3, 3)
        Select Case exteN
            Case Is = "fp1", "fp2", "me0", "cb8", "br9", "em3", "sp4", "ds1", "qs5", "qs6", "we1", "ap7", "xl1", "xl2"
                Dim pos As Integer = sFilePathOpen.LastIndexOf("\")
                txbSCSfileName.Text = sFilePathOpen.Substring(pos + 1, sFilePathOpen.Length - (pos + 1))
                WorkingPath = sFilePathOpen.Substring(0, pos + 1)
            Case Else
                MsgBox("this is not a valid SCS file")
        End Select
    End Sub

    Private Sub txbSapFileName_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txbSapFileName.TextChanged

    End Sub
End Class
Public Class FrameElement
    Private m_label As String
    Public Property Label() As String
        Get
            Return m_label
        End Get
        Set(ByVal value As String)
            m_label = value
        End Set
    End Property
    Public Sub New()
    End Sub
    Private m_coordpoint1(2) As Double
    Private m_coordpoint2(2) As Double
    Public Property CoordPoint1() As Double()
        Get
            Return m_coordpoint1
        End Get
        Set(ByVal value As Double())
            m_coordpoint1 = value
        End Set
    End Property
    Public Property CoordPoint2() As Double()
        Get
            Return m_coordpoint2
        End Get
        Set(ByVal value As Double())
            m_coordpoint2 = value
        End Set
    End Property
    Public Sub New(ByVal label As String, ByVal coord1() As Double, ByVal coord2() As Double)
        m_label = label
        If coord1.Count = 3 Then m_coordpoint1 = coord1
        If coord2.Count = 3 Then m_coordpoint2 = coord2
    End Sub
    Private m_vector(2) As Double
    Private m_vectornormalized(2) As Double
    Private m_length As Double
    Public ReadOnly Property VectorNormalized() As Double()
        Get
            For k = 0 To 2
                m_vector(k) = m_coordpoint2(k) - m_coordpoint1(k)
            Next
            m_length = Sqrt(m_vector(0) ^ 2 + m_vector(1) ^ 2 + m_vector(2) ^ 2)
            For k = 0 To 2
                m_vectornormalized(k) = m_vector(k) / m_length
            Next
            Return m_vectornormalized
        End Get
    End Property
    Public ReadOnly Property MainDirection_0x_1y_2z_3xyPlane_4xzplane_5yzplane_6xyz() As Integer
        Get
            Dim refVal As Double = 0.95 'this means an angle approx between 72° and 90°
            Dim refVal2 As Double = 0.05
            If Abs(VectorNormalized(0)) >= refVal Then
                Return 0
            ElseIf Abs(m_vectornormalized(1)) >= refVal Then
                Return 1
            ElseIf Abs(m_vectornormalized(2)) >= refVal Then
                Return 2
            ElseIf Abs(m_vectornormalized(2)) <= refVal2 Then
                Return 3
            ElseIf Abs(m_vectornormalized(1)) <= refVal2 Then
                Return 4
            ElseIf Abs(m_vectornormalized(0)) <= refVal2 Then
                Return 5
            Else
                Return 6
            End If
        End Get
    End Property
End Class

Module CommonMethods
    Public Function AngleBetweenFrameElements(ByVal Frame1 As FrameElement, ByVal Frame2 As FrameElement) As Double 'angle in radians between frame elements
        Dim angleinRadians As Double = Acos(Frame1.VectorNormalized(0) * Frame2.VectorNormalized(0) + Frame1.VectorNormalized(1) * Frame2.VectorNormalized(1) + Frame1.VectorNormalized(2) * Frame2.VectorNormalized(2))
        If angleinRadians >= PI Then angleinRadians += -PI
        Return angleinRadians
    End Function
End Module

Public Class Sap2000JointData
    Private m_primarymemberisacolumn As Boolean = False
    Private m_frameelements() As FrameElement
    Private m_objname() As String
    Private m_pointnumber() As Integer
    Private m_propertyname() As String
    Private m_propertyrefvalue() As Double
    Private m_propertyrefvaluesorted() As Double
    Private m_objectcount As Integer
    Private m_objnameroot() As String
    Private m_objnode() As Integer '0 first joint, 1 second joint
    Private m_objnamesecondpart() As String
    Private m_baseplatejoint As Boolean = False
    Private m_bracejoint As Boolean = False
    Public Property BraceJoint() As Boolean
        Get
            Return m_bracejoint
        End Get
        Set(ByVal value As Boolean)
            m_bracejoint = value
        End Set
    End Property
    Public Property BasePlateJoint() As Boolean
        Get
            Return m_baseplatejoint
        End Get
        Set(ByVal value As Boolean)
            m_baseplatejoint = value
        End Set
    End Property
    Public Property ObjNode() As Integer()
        Get
            Return m_objnode
        End Get
        Set(ByVal value() As Integer)
            m_objnode = value
        End Set
    End Property
    Public Property PrimaryMemberIsaColumn() As Boolean
        Get
            Return m_primarymemberisacolumn
        End Get
        Set(ByVal value As Boolean)
            m_primarymemberisacolumn = value
        End Set
    End Property
    Public Property FrameElements() As FrameElement()
        Get
            Return m_frameelements
        End Get
        Set(ByVal value() As FrameElement)
            m_frameelements = value
        End Set
    End Property
    Public ReadOnly Property ObjectCount() As Integer
        Get
            Return m_objectcount
        End Get
    End Property
    Public Property ObjName() As String()
        Get
            Return m_objname
        End Get
        Set(ByVal value As String())
            m_objname = value
        End Set
    End Property
    Public Property PointNumber() As Integer()
        Get
            Return m_pointnumber
        End Get
        Set(ByVal value As Integer())
            m_pointnumber = value
        End Set
    End Property
    Public Property PropertyRefValue() As Double()
        Get
            Return m_propertyrefvalue
        End Get
        Set(ByVal value As Double())
            m_propertyrefvalue = value
        End Set
    End Property
    Public Property PropertyName() As String()
        Get
            Return m_propertyname
        End Get
        Set(ByVal value As String())
            m_propertyname = value
        End Set
    End Property
    Public Sub New(ByVal objcount As Integer)
        m_objectcount = objcount
        If m_objectcount = 0 Then
            MsgBox("problem")
        End If
        ReDim m_pointnumber(m_objectcount - 1)
        ReDim m_objname(m_objectcount - 1)
        ReDim m_propertyname(m_objectcount - 1)
        ReDim m_objnameroot(m_objectcount - 1)
        ReDim m_objnode(m_objectcount - 1)
        ReDim m_objnamesecondpart(m_objectcount - 1)
        ReDim m_propertyrefvalue(m_objectcount - 1)
        ReDim m_propertyrefvaluesorted(m_objectcount - 1)
    End Sub
    Private m_guessedprimarymember_name As String
    Private m_guessedsecondarymember_name() As String
    Public Property GuessedPrimaryMember_Name() As String
        Get
            Return m_guessedprimarymember_name
        End Get
        Set(ByVal value As String)
            m_guessedprimarymember_name = value
        End Set
    End Property
    Public Property GuessedSecondaryMember_Name() As String()
        Get
            Return m_guessedsecondarymember_name
        End Get
        Set(ByVal value() As String)
            m_guessedsecondarymember_name = value
        End Set
    End Property
    Private m_guessedprimarymember_property_OverWrite As Boolean = False
    Public Property GuessedPrimaryMember_property_OverWrite() As Boolean
        Get
            Return m_guessedprimarymember_property_OverWrite
        End Get
        Set(ByVal value As Boolean)
            m_guessedprimarymember_property_OverWrite = value
            CheckIfCustomAssignedPrimaryMemberPropertyIsOkInThisJoint()
        End Set
    End Property
    Private Sub CheckIfCustomAssignedPrimaryMemberPropertyIsOkInThisJoint()
        If m_baseplatejoint = False Then
            If m_guessedprimarymember_property_OverWrite Then
                Dim booCheckIsOk = False
                For j = 0 To m_objectcount - 1
                    If m_guessedprimarymember_property = m_propertyname(j) Then
                        m_guessedprimarymember_name = m_objname(j)
                        m_guessedprimarymember_index = j
                        booCheckIsOk = True
                        Exit For
                    End If
                Next
                If booCheckIsOk Then
                    m_jointisverifiedtogiveloads = True
                Else
                    m_jointisverifiedtogiveloads = False
                    MsgBox("Joint " & m_label & " doesn't have any member connected with the primary member property " & m_guessedprimarymember_property & _
                            "therefore its load data will not be included in the export")
                End If
            End If
        End If
    End Sub
    Private m_jointisverifiedtogiveloads As Boolean = False
    Public ReadOnly Property JointIsVerifiedToGiveLoads() As Boolean 'this is false when the primary member property assigned can't be found in the joint
        Get
            Return m_jointisverifiedtogiveloads
        End Get
    End Property
    Private m_guessedprimarymember_property As String
    Private m_guessedsecondarymember_property As String
    Public Property GuessedPrimaryMember_property() As String
        Get
            If m_guessedprimarymember_property_OverWrite = False Then m_guessedprimarymember_property = m_propertyname(GuessedPrimaryMember_index)
            Return m_guessedprimarymember_property
        End Get
        Set(ByVal value As String)
            m_guessedprimarymember_property = value
            CheckIfCustomAssignedPrimaryMemberPropertyIsOkInThisJoint()
        End Set
    End Property
    Public Property GuessedSecondaryMember_property() As String
        Get
            Return m_guessedsecondarymember_property
        End Get
        Set(ByVal value As String)
            m_guessedsecondarymember_property = value
        End Set
    End Property
    Private m_guessedprimarymember_index As String
    Private m_guessedsecondarymember_index() As String
    Public ReadOnly Property GuessedPrimaryMember_index() As String
        Get
            ' m_guessedprimarymember_index = GetIndexByObjName(m_guessedprimarymember_name)
            Return m_guessedprimarymember_index
        End Get
        'Set(ByVal value As String)
        '    m_guessedprimarymember_index = value
        'End Set
    End Property
    Public ReadOnly Property GuessedSecondaryMember_index() As String()
        Get
            'For i = 0 To m_guessedsecondarymember_name.Count - 1
            '    m_guessedsecondarymember_index(i) = GetIndexByObjName(m_guessedsecondarymember_name(i))
            'Next
            Return m_guessedsecondarymember_index
        End Get
        'Set(ByVal value As String)
        '    m_guessedsecondarymember_index = value
        'End Set
    End Property
    Private Function GetIndexByObjName(ByVal name As String) As Integer
        For k = 0 To m_objectcount - 1
            If m_objname(k) = name Then
                Return k
            End If
        Next
        Return Nothing
    End Function
    Public ReadOnly Property ObjectNameRoot() As String()
        Get
            Return m_objnameroot
        End Get
    End Property
    Private m_label As String
    Public Property Label() As String
        Get
            Return m_label
        End Get
        Set(ByVal value As String)
            m_label = value
        End Set
    End Property
    Private m_listofsecondarymember
    Public Sub GetObjNameRoot(ByVal j As Integer)
        m_objnameroot(j) = m_objname(j).Substring(0, m_objname(j).LastIndexOf("-"))
        m_objnamesecondpart(j) = m_objname(j).Substring(m_objname(j).LastIndexOf("-") + 1, m_objname(j).Length - m_objname(j).LastIndexOf("-") - 1)
    End Sub
    Private m_SecMembersInThisJointCount As Integer = 0
    Private m_PrimMembersInThisJointCount As Integer = 0
    Public Sub GuessPrimaryMembersAndAssignSecMembers(ByVal SecMembers As String())
        m_SecMembersInThisJointCount = 0
        For j = 0 To m_objectcount - 1
            'GetObjNameRoot(j) not needed since it has been called to assign values to FrameElements
            For i = 0 To SecMembers.Count - 1
                If m_objnameroot(j) = SecMembers(i) Then
                    ReDim Preserve m_guessedsecondarymember_name(m_SecMembersInThisJointCount)
                    ReDim Preserve m_guessedsecondarymember_index(m_SecMembersInThisJointCount)
                    m_guessedsecondarymember_name(m_SecMembersInThisJointCount) = m_objname(j)
                    m_guessedsecondarymember_index(m_SecMembersInThisJointCount) = j
                    m_guessedsecondarymember_property = m_propertyname(j)  'revision on 20141127
                    m_SecMembersInThisJointCount += 1
                End If
            Next
        Next
        If m_SecMembersInThisJointCount = 0 Then
            MsgBox("no secondary member selected for joint " & m_label)
            m_jointisverifiedtogiveloads = False
        Else
            m_PrimMembersInThisJointCount = 0
            For j = 1 To m_objectcount - 1
                For k = 0 To m_SecMembersInThisJointCount - 1
                    If j <> m_guessedsecondarymember_index(k) Then
                        Dim anG As Double = AngleBetweenFrameElements(m_frameelements(m_guessedsecondarymember_index(k)), m_frameelements(j))
                        Dim angDegrees As Double = anG / PI * 180
                        If Abs(90 - angDegrees) <= acceptedangleDeltafrom90 Then
                            m_guessedprimarymember_name = m_objname(j)
                            m_guessedprimarymember_index = j
                            m_jointisverifiedtogiveloads = True
                        End If
                    End If
                Next
            Next
        End If

    End Sub
    Private Function acceptedangleDeltafrom90() As Double
        If m_bracejoint Then
            Return 75
        Else
            Return 15
        End If
    End Function

End Class
  
Please note the following, valid for all the examples:
- you need to be skilled with programming to make it work, we don't provide assistance for macros, only the API side if there are questions;
- you can use free sofware tools like Visual Studio Express to modify and compile it;
- the macro is just an example and can be modified and improved; some logic (like the maximum load and combinations among loads) can be modified too, as everything: we just give you an example and a set of tools then it's up to you to make it work the way you want it.

Export joints to Tekla; and import from Tekla! Download code and forms
While a more complete version for importing and exporting joints from and to Tekla will be coming soon and it will be, as for Staad and Sap2000, a built in button inside SCS, a possible example of a macro for letting SCS and Tekla exchange files is below copied. Just if you can't wait..... The macro is pretty basic since the SCS file to import/export is chosen programattically and only some SCS connection types can be exported. Again, it's just a simple example. It was developed with Visual Studio Express 2013 for Desktop in C#.
Tekla connections design import and export

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using mySCS;
// Tekla Structures Namespaces
using Tekla.Structures;
using Tekla.Structures.Model;
using Tekla.Structures.Geometry3d;
using Tekla.Structures.Model.UI;
using TSM = Tekla.Structures.Model;
using T3D = Tekla.Structures.Geometry3d;
using TSMUI = Tekla.Structures.Model.UI;
using TSO = Tekla.Structures.Model.Operations;
// Additional Namespace references
using System.IO;
using System.Collections;
using System.Diagnostics;

namespace SCSandTekla
{
    public partial class TeklaImporExport : Form
    {
         mySCS.frmShapedStart SCSobj;
         mySCS.frmFP1 SCSmod0;
         TSM.Connection myConn;
         TSM.Model myModel;
         string FileName;
         string k = "";
         string k1 = "";
         double w = 0.0;
         int j = 0;
         string Extn;

      public TeklaImporExport() 
        {
           InitializeComponent();
           
           SCSobj = new mySCS.frmShapedStart();
           SCSobj.ApplicationStart();
          FileName = "yourpath/test1.xl1"; //write the path to your file here
           SCSobj.OpenFileAndAssignGenericModuleObject(FileName, ref SCSmod0);
           Extn = SCSmod0.Extension;  
           myModel = new TSM.Model();
           myConn = new TSM.Connection();
        }
        
        private void btnToTekla_Click(object sender, EventArgs e) 
        {
            string ConnName = "";
            claDataPage_General.PlateWeldingtoPrimary k2;
            k2 = SCSmod0.DataPage_General.PlateWeldingtoPrimarySelection;
            switch (Extn)
            {
                case ".fp1":
                    {
                        ConnName = "Fin Plate fp1 SCS";
                        myConn.Number = 103;
                        break;
                    }
                case ".fp2":
                    {
                        ConnName = "Fin plate fp2 SCS";
                        if (k2 == claDataPage_General.PlateWeldingtoPrimary.FirstOption)
                        {
                           myConn.Number = 146;
                        }
                        if (k2== claDataPage_General.PlateWeldingtoPrimary.SecondOption)
                        {
                           myConn.Number = 149;
                        }
                        if (k2== claDataPage_General.PlateWeldingtoPrimary.ThirdOption)
                        {
                           myConn.Number = 185;
                        }
                        break;
                    }
                case ".xl1":
                    {
                        ConnName = "Flexible End Plate xl1 SCS";
                        myConn.Number = 29;
                        break;
                    }
                case ".xl2":
                    {
                        ConnName = "Flexible End Plate xl2 SCS";
                        myConn.Number = 101;
                        break;
                    }
                case ".sp4":
                    {
                        ConnName = "Splice sp4 SCS";
                        myConn.Number = 132;
                        break;
                    }
            }
            myConn.Name = ConnName;
            myConn.UpVector = new Tekla.Structures.Geometry3d.Vector(0, 0, 1000);
            myConn.PositionType = Tekla.Structures.PositionTypeEnum.COLLISION_PLANE;
            // TODO : check units (mm, inches)
            // this.Hide();
            // Dim myMainPart As TSM.Part = TSM.UI.Picker.PickObjectEnum.PICK_ONE_OBJECT
            // TSM.UI.PickerickObject(Picker.PickObjectEnum.PICK_ONE_PART, "PickColumn")
            MessageBox.Show("Select Primary and Secondary Sections in TS 20.0");
            // SelectedBeam = PartPicker.PickObject(Picker.PickObjectEnum.PICK_ONE_PART, "Pick Beam")
            Tekla.Structures.Model.UI.Picker myPicker = new Tekla.Structures.Model.UI.Picker();
            Tekla.Structures.Model.ModelObject myTSObj = default(Tekla.Structures.Model.ModelObject);
            // Selecting Primary
            myTSObj = myPicker.PickObject(Tekla.Structures.Model.UI.Picker.PickObjectEnum.PICK_ONE_OBJECT, "Select Primary Part");
            TSM.Part myMainPart = null;
            if (myTSObj is Tekla.Structures.Model.Part)
            {
                myMainPart = myTSObj as TSM.Part;
            }
            else
            {
                MessageBox.Show("Select a Part");
                myTSObj = myPicker.PickObject(Tekla.Structures.Model.UI.Picker.PickObjectEnum.PICK_ONE_OBJECT, "Select Primary Section");
            }
            // Selecting Secondary
            myTSObj = myPicker.PickObject(Tekla.Structures.Model.UI.Picker.PickObjectEnum.PICK_ONE_OBJECT, "Select Secondary Part");
            TSM.Part mySecPart = null;
            if (myTSObj is Tekla.Structures.Model.Part)
            {
                mySecPart = myTSObj as TSM.Part;
            }
            else
            {
                MessageBox.Show("Select a Part");
                myTSObj = myPicker.PickObject(Tekla.Structures.Model.UI.Picker.PickObjectEnum.PICK_ONE_OBJECT, "Select a Secondary Part");
            }
            //  MsgBox(myMainPart.Profile.ProfileString & " x " & mySecPart.Profile.ProfileString)
            this.Show();
            myConn.SetPrimaryObject(myMainPart);
            myConn.SetSecondaryObject(mySecPart);
            // CC Data............................................................................................................................
            // myConn.Code = myConn.Number + "-001";
            // Bolt Data..........................................................................................................................
            double myBoltDia = Convert.ToDouble(SCSmod0.DataPage_PlateandBolts.BoltDiameter);
            double myBoltHole = Convert.ToDouble(SCSmod0.DataPage_PlateandBolts.HoleDiameter);
            // Not able to read Bolt Mat
            string myBoltGrade = "UNI5737-8.8"; //change this as required and available
            double myFirstBoltPosition = Convert.ToDouble(SCSmod0.DataPage_Geometry.aVertBeamTop);
            double myEndDist_Plate = Convert.ToDouble(SCSmod0.DataPage_Geometry.aVerticalBoltPlateTop);
            double myDist_Beam_Plate = myFirstBoltPosition-myEndDist_Plate;
            double myEdgeDist_Beam = 0.0; // Convert.ToDouble(SCSmod0.DataPage_Geometry.aHorizBeam);
            double myEdgeDist_Plate = 0.0; // Convert.ToDouble(SCSmod0.DataPage_Geometry.aHrizontalPlate);
            double myHor_Gauge = Convert.ToDouble(SCSmod0.DataPage_Geometry.BoltHorizontalGauge); 
            // Plate Attributes...................................................................................................................
            double myPlateThk = Convert.ToDouble(SCSmod0.DataPage_Geometry.PlateThickness);
            double myPlateWidth = Convert.ToDouble(SCSmod0.DataPage_Geometry.PlateWidth);
            double myPlateDepth = Convert.ToDouble(SCSmod0.DataPage_Geometry.PlateDepth);
            double myDist_Beam_Column = 0.0;
            double myColumnStiffThk = 0.0; // Convert.ToDouble(SCSmod0.DataPage_WeldNotchStiffeners.PrimaryMemberStiffenerThickness);
            double myBeamNotchLength = 0.0;
            double myBeamNotchDepth = 0.0;
            double myBeamNotchRadius =  0.0;
            int myBoltColumns = Convert.ToInt16(SCSmod0.DataPage_Geometry.BoltColumns); ;
            string myPlateMaterial = SCSmod0.DataPage_PlateandBolts.PlateMaterial;

            myConn.SetAttribute("diameter", myBoltDia);
            myConn.SetAttribute("tolerance", myBoltHole - myBoltDia);
            myConn.SetAttribute("screwdin", myBoltGrade);
            k = SCSmod0.DataPage_Geometry.BoltRows;
            OperatewithTekla(0, 2, "nb", ref k, ref myConn);
            k = SCSmod0.DataPage_Geometry.BoltVerticalPitch;
            OperatewithTekla(0, 0, "lbd", ref k, ref myConn);
            if (myBoltColumns > 1)
            {
               k = SCSmod0.DataPage_Geometry.BoltHorizontalGauge;
            }
            else
            {
               k = "-2147483648";
            }
            OperatewithTekla(0, 0, "lwd", ref k, ref myConn);
            myConn.SetAttribute("rb1", myEndDist_Plate);
            myConn.SetAttribute("nw", myBoltColumns);
            // Plate Parameters 
            myConn.SetAttribute("tpl1", myPlateThk);
            myConn.SetAttribute("hpl1", myPlateDepth);
            // todo plate material
            // todo washers
            // todo slots
            // todo welds: throat or leg, [mm] or [inch]

            switch (Extn)
            {
                case ".fp1":
                     {
                         myDist_Beam_Column = Convert.ToDouble(SCSmod0.DataPage_Geometry.BeamClearance);
                         myEdgeDist_Beam = Convert.ToDouble(SCSmod0.DataPage_Geometry.aHorizBeam);
                         myEdgeDist_Plate = Convert.ToDouble(SCSmod0.DataPage_Geometry.aHrizontalPlate);
                         myConn.SetAttribute("e1", myDist_Beam_Plate);
                         myConn.SetAttribute("lba", myFirstBoltPosition);
                         myConn.SetAttribute("dv", myDist_Beam_Column);
                         w = myDist_Beam_Column + myEdgeDist_Beam;
                         myConn.SetAttribute("rw1", w);
                         myConn.SetAttribute("rw2", myEdgeDist_Plate);
                         myConn.SetAttribute("lbtyp", 1);
                         myConn.SetAttribute("bpl1", myPlateWidth);
                         myConn.SetAttribute("w1_type", 10);
                         k = SCSmod0.DataPage_WeldNotchStiffeners.WeldWeb_Thickness;
                         OperatewithTekla(0, 2, "w1_size", ref k, ref myConn);
                         myConn.SetAttribute("w1_type2", 0);
                         myConn.SetAttribute("w1_size2", -2147483648);
                         claDataPage_WeldNotchesandStiffeners.WeldTypeofWebWeld k3;
                         k3 = SCSmod0.DataPage_WeldNotchStiffeners.WeldTypeofWebWeldSelection;
                         if (k3 == claDataPage_WeldNotchesandStiffeners.WeldTypeofWebWeld.SingleFillet)
                         {
                         }
                         if (k3 == claDataPage_WeldNotchesandStiffeners.WeldTypeofWebWeld.DoubleFillet)
                         {
                             myConn.SetAttribute("w1_type2", 10);
                             k1 = SCSmod0.DataPage_WeldNotchStiffeners.WeldWeb_Thickness;
                             OperatewithTekla(0, 2, "w1_size2", ref k1, ref myConn);
                         }
                         if (k3 == claDataPage_WeldNotchesandStiffeners.WeldTypeofWebWeld.CompletePenetration)
                         {
                             myConn.SetAttribute("w1_type", 4);
                             myConn.SetAttribute("w1_size", 0);
                         }      
                         break;
                     }
                case ".fp2":
                     {
                         myEdgeDist_Plate = Convert.ToDouble(SCSmod0.DataPage_Geometry.aHrizontalPlate); 
                         myConn.SetAttribute("rw1", myEdgeDist_Plate);
                         myConn.SetAttribute("lbtyp", 1);
                         myEdgeDist_Beam = Convert.ToDouble(SCSmod0.DataPage_Geometry.aHorizBeam);
                         myConn.SetAttribute("lwa", myEdgeDist_Beam);
                         myConn.SetAttribute("lba", myFirstBoltPosition);
                         myConn.SetAttribute("btab3", 2);
                         myConn.SetAttribute("bpl1", myPlateWidth);
                         claDataPage_WeldNotchesandStiffeners.Notch k4;
                         k4 = SCSmod0.DataPage_WeldNotchStiffeners.NotchSelection;
                         if (k2 == claDataPage_General.PlateWeldingtoPrimary.FirstOption) // welded only on web
                         {
                             myDist_Beam_Column = Convert.ToDouble(SCSmod0.DataPage_Geometry.BeamClearance);
                             myConn.SetAttribute("dv", myDist_Beam_Column);
                         }
                         else // claDataPage_General.PlateWeldingtoPrimary.SecondOption | claDataPage_General.PlateWeldingtoPrimary.ThirdOption) // welded to top flange | full depth
                         {
                             myConn.SetAttribute("hpl1", -2147483648.0);
                             myConn.SetAttribute("rb2", myEndDist_Plate);
                             k = SCSmod0.DataPage_Geometry.BeamClearanceFlanges;
                             OperatewithTekla(0, 1, "dv", ref k, ref myConn);
                             if (k4 == claDataPage_WeldNotchesandStiffeners.Notch.TopNotch | k4 == claDataPage_WeldNotchesandStiffeners.Notch.TopandBottomNotch)
                             {
                                 OperatewithTekla(0, 1, "skew", ref k, ref myConn);
                             }
                             else
                             {
                                 myConn.SetAttribute("skew", 0.0);
                             }
                             myConn.SetAttribute("btab2", 2);
                         }
                         if (k2 == claDataPage_General.PlateWeldingtoPrimary.ThirdOption) // full depth only
                         {
                             //myConn.SetAttribute("edist3", -2147483648.0)
                             //myConn.SetAttribute("tol3", -2147483648.0)
                             myConn.SetAttribute("skew", 0.0);
                         }
                         myConn.SetAttribute("t_cope_length", 0.0);
                         myConn.SetAttribute("t_cope_depth", 0.0);
                         if (k4 != claDataPage_WeldNotchesandStiffeners.Notch.NoNotch)
                         {
                             myBeamNotchLength = Convert.ToDouble(SCSmod0.DataPage_WeldNotchStiffeners.NotchLength);
                             myBeamNotchDepth  = Convert.ToDouble(SCSmod0.DataPage_WeldNotchStiffeners.NotchDepth);
                             myBeamNotchRadius = Convert.ToDouble(SCSmod0.DataPage_WeldNotchStiffeners.NotchRadius);
                         }
                         else // no notch case
                         {
                             myConn.SetAttribute("cope_fitting_type2", -2147483648);
                             myConn.SetAttribute("t_cut_width2", -2147483648.0);
                             myConn.SetAttribute("etab4", -2147483648);
                             myConn.SetAttribute("t_cut_length",  -2147483648.0);
                             myConn.SetAttribute("b_cope_length", -2147483648.0);
                             myConn.SetAttribute("t_cut_width2", -2147483648.0);
                             myConn.SetAttribute("etab3", -2147483648);
                             myConn.SetAttribute("b_cut_length", -2147483648.0);
                             myConn.SetAttribute("b_cope_depth", -2147483648.0);
                         }
                         if (k4 == claDataPage_WeldNotchesandStiffeners.Notch.TopNotch |  k4 == claDataPage_WeldNotchesandStiffeners.Notch.TopandBottomNotch)
                         {
                             myConn.SetAttribute("etab4", 1);
                             myConn.SetAttribute("cope_fitting_type2", 2);
                             myConn.SetAttribute("t_cut_length", myBeamNotchLength);
                             myConn.SetAttribute("b_cope_length", myBeamNotchDepth);
                             myConn.SetAttribute("t_cut_width2", myBeamNotchRadius);
                             w = myFirstBoltPosition + myBeamNotchDepth;
                             myConn.SetAttribute("lba", w); 
                         }
                         if (k4 == claDataPage_WeldNotchesandStiffeners.Notch.BottomNotch |  k4 == claDataPage_WeldNotchesandStiffeners.Notch.TopandBottomNotch)
                         {
                             myConn.SetAttribute("etab3", 1);
                             myConn.SetAttribute("cope_fitting_type2", 2);
                             myConn.SetAttribute("b_cut_length", myBeamNotchLength);
                             myConn.SetAttribute("b_cope_depth", myBeamNotchDepth);
                             myConn.SetAttribute("t_cut_width2", myBeamNotchRadius);
                         }
                         if (SCSmod0.DataPage_WeldNotchStiffeners.CheckBoxOneStiffnerPrimaryMember == true)
                         {
                             myConn.SetAttribute("atab3", 0);
                             myColumnStiffThk = Convert.ToDouble(SCSmod0.DataPage_WeldNotchStiffeners.PrimaryMemberStiffenerThickness);
                             myConn.SetAttribute("tj3", myColumnStiffThk);
                             myConn.SetAttribute("tol2", 1.0); // for a default value, use: ("tol2", -2147483648.0);
                         }
                         else
                         {
                             myConn.SetAttribute("atab3",3);
                             myConn.SetAttribute("tol2", -2147483648.0);
                         }
                         break;
                     }
                case ".xl1":
                     {
                         myConn.SetAttribute("e1", myDist_Beam_Plate);
                         myConn.SetAttribute("lba", myFirstBoltPosition);
                         w = (Convert.ToDouble(SCSmod0.DataPage_Geometry.PlateWidth) - Convert.ToDouble(SCSmod0.DataPage_Geometry.BoltHorizontalGauge))/2; 
                         myConn.SetAttribute("rw1", w);
                         myConn.SetAttribute("rw2", w);
                         k = "2"; // reference for bolts in Tekla: 1 left, 2 middle, 3 right;
                         OperatewithTekla(0, 2, "lwtyp", ref k, ref myConn); 
                         k = "0";
                         OperatewithTekla(0, 1, "lwa", ref k, ref myConn);   // hor. distance between plate and reference for bolts
                         k = "-2147483648";
                         OperatewithTekla(0, 1, "dv", ref k, ref myConn);   // space between end plate and column
                         myConn.SetAttribute("bpl1", myPlateWidth); 
                         // OperatewithTekla(0, 1, "rb2", ref k, ref myConn); 
                         myConn.SetAttribute("w1_type", 10);
                         myConn.SetAttribute("w1_type2", 10);
                         myConn.SetAttribute("w2_type", 10);
                         myConn.SetAttribute("w2_type2", 10);
                         myConn.SetAttribute("w3_type", 10);
                         myConn.SetAttribute("w3_type2", 10);
                         //  todo a o z, mm o inch, symbols according to standard
                         k = SCSmod0.DataPage_WeldNotchStiffeners.WeldFlange_Thickness;
                         OperatewithTekla(0, 2, "w1_size", ref k, ref myConn);
                         OperatewithTekla(0, 2, "w1_size2", ref k, ref myConn);
                         OperatewithTekla(0, 2, "w2_size", ref k, ref myConn);
                         OperatewithTekla(0, 2, "w2_size2", ref k, ref myConn);
                         k = SCSmod0.DataPage_WeldNotchStiffeners.WeldWeb_Thickness;
                         OperatewithTekla(0, 2, "w3_size", ref k, ref myConn);
                         OperatewithTekla(0, 2, "w3_size2", ref k, ref myConn);
                         claDataPage_WeldNotchesandStiffeners.WeldTypeofFlangeWeld k5;
                         k5 = SCSmod0.DataPage_WeldNotchStiffeners.WeldTypeofFlangeWeldSelection;
                         if (k5 == claDataPage_WeldNotchesandStiffeners.WeldTypeofFlangeWeld.SingleFillet)
                         {
                             myConn.SetAttribute("w1_type", 0);
                             myConn.SetAttribute("w1_size", -2147483648);
                             myConn.SetAttribute("w2_type", 0);
                             myConn.SetAttribute("w2_size", -2147483648);
                         }
                         if (k5 == claDataPage_WeldNotchesandStiffeners.WeldTypeofFlangeWeld.CompletePenetration)
                         {
                             myConn.SetAttribute("w1_type", 4);
                             myConn.SetAttribute("w1_type2", 0);
                             myConn.SetAttribute("w1_size", -2147483648);
                             myConn.SetAttribute("w1_size2", -2147483648);
                             myConn.SetAttribute("w2_type2", 4);
                             myConn.SetAttribute("w2_type", 0);
                             myConn.SetAttribute("w2_size2", -2147483648);
                             myConn.SetAttribute("w2_size", -2147483648);
                         }
                         claDataPage_WeldNotchesandStiffeners.WeldTypeofWebWeld k6;
                         k6 = SCSmod0.DataPage_WeldNotchStiffeners.WeldTypeofWebWeldSelection;
                         if (k6 == claDataPage_WeldNotchesandStiffeners.WeldTypeofWebWeld.CompletePenetration)
                         {
                             myConn.SetAttribute("w3_type", 4);
                             myConn.SetAttribute("w3_type2", 0);
                             myConn.SetAttribute("w3_size", -2147483648);
                             myConn.SetAttribute("w3_size2", -2147483648);
                         }
                         break;
                     }
                case ".xl2":
                        {
                         myConn.SetAttribute("e1", myDist_Beam_Plate);
                         w = (Convert.ToDouble(SCSmod0.DataPage_Geometry.PlateWidth) - Convert.ToDouble(SCSmod0.DataPage_Geometry.BoltHorizontalGauge))/2; 
                         myConn.SetAttribute("rw1", w);
                         myConn.SetAttribute("rw2", w);
                         k = "2";
                         OperatewithTekla(0, 2, "lwtyp", ref k, ref myConn); // reference for bolts in Tekla: 1 left, 2 middle, 3 right;
                         k = "0";
                         OperatewithTekla(0, 1, "lwa", ref k, ref myConn);   // hor. distance between plate and reference for bolts
                         k = "-2147483648";
                         OperatewithTekla(0, 1, "dv", ref k, ref myConn);   // space between end plate and column
                         claDataPage_WeldNotchesandStiffeners.Notch k7;
                         k7 = SCSmod0.DataPage_WeldNotchStiffeners.NotchSelection;
                         if (k7 != claDataPage_WeldNotchesandStiffeners.Notch.NoNotch)
                         {
                            myBeamNotchLength = Convert.ToDouble(SCSmod0.DataPage_WeldNotchStiffeners.NotchLength);
                            myBeamNotchDepth = Convert.ToDouble(SCSmod0.DataPage_WeldNotchStiffeners.NotchDepth);
                            myBeamNotchRadius = Convert.ToDouble(SCSmod0.DataPage_WeldNotchStiffeners.NotchRadius);
                            myConn.SetAttribute("cut2", 0);
                         }
                         if (k7 == claDataPage_WeldNotchesandStiffeners.Notch.TopNotch | k7 == claDataPage_WeldNotchesandStiffeners.Notch.TopandBottomNotch)
                         {
                            myConn.SetAttribute("bdist1", myBeamNotchDepth);
                            myConn.SetAttribute("adist1", myBeamNotchLength);
                            myConn.SetAttribute("epr1", 1);
                            w = myFirstBoltPosition + myBeamNotchDepth;
                            myConn.SetAttribute("lba", w);  // overwrite for .xl2 case
                         }
                         if (k7 == claDataPage_WeldNotchesandStiffeners.Notch.BottomNotch | k7 == claDataPage_WeldNotchesandStiffeners.Notch.TopandBottomNotch)
                         {
                            myConn.SetAttribute("bdist2", myBeamNotchDepth);
                            myConn.SetAttribute("adist2", myBeamNotchLength);
                            myConn.SetAttribute("epr2", 1);
                         }
                         break;
                     }
                case ".sp4":
                     {
                         k = SCSmod0.DataPage_Geometry.BeamClearance;
                         OperatewithTekla(0, 2, "dv", ref k, ref myConn);
                         // flange bolts parameters
                         k = SCSmod0.DataPage_Geometry.BoltColumns;
                         OperatewithTekla(0, 2, "nb", ref k, ref myConn);
                         k = SCSmod0.DataPage_Geometry.BoltHorizontalGauge;
                         OperatewithTekla(0, 0, "lbd", ref k, ref myConn);
                         k = SCSmod0.DataPage_Geometry.aHrizontalPlate;
                         OperatewithTekla(0, 1, "rb1", ref k, ref myConn);
                         k = SCSmod0.DataPage_Geometry.aHorizBeam;
                         OperatewithTekla(0, 1, "lba", ref k, ref myConn);
                         k = Convert.ToString(2 * Convert.ToDouble(SCSmod0.DataPage_Geometry.BoltRows));
                         OperatewithTekla(0, 2, "nw", ref k, ref myConn);
                         k = SCSmod0.DataPage_Geometry.PlateDepth;
                         k= Convert.ToString(Convert.ToDouble(k)-2*Convert.ToDouble(SCSmod0.DataPage_Geometry.aVerticalBoltPlateTop));
                         OperatewithTekla(0, 0, "lwd", ref k, ref myConn);
                         k = SCSmod0.DataPage_Geometry.aVerticalBoltPlateTop;
                         OperatewithTekla(0, 1, "rw1", ref k, ref myConn);
                         // web bolts parameters
                         k = SCSmod0.DataPage_PlateandBolts.BoltDiameterBoltGroup2;
                         OperatewithTekla(0,2, "diameter2", ref k, ref myConn);
                         k1 = SCSmod0.DataPage_PlateandBolts.HoleDiamBoltGroup2;
                         k1 = Convert.ToString(Convert.ToDouble(k1) - Convert.ToDouble(k));
                         OperatewithTekla(0, 2, "tolerance2", ref k1, ref myConn);
                         myConn.SetAttribute("screwdin2", myBoltGrade); // so, it's the same of flange bolts
                         k = SCSmod0.DataPage_Geometry.BoltColumnsBoltGroup2;
                         OperatewithTekla(0, 2, "nb2", ref k, ref myConn);
                         k = SCSmod0.DataPage_Geometry.BoltHorizontalGaugeBoltGroup2;
                         OperatewithTekla(0, 0, "lbd2", ref k, ref myConn); 
                         k = SCSmod0.DataPage_Geometry.aHorizontalPlateBoltGroup2;
                         OperatewithTekla(0, 2, "rb21", ref k, ref myConn);
                         k = SCSmod0.DataPage_Geometry.BoltVerticalPitchBoltGroup2;
                         OperatewithTekla(0, 0, "lwd2", ref k, ref myConn);
                         k = SCSmod0.DataPage_Geometry.BoltRowsBoltGroup2;
                         OperatewithTekla(0, 2, "nw2", ref k, ref myConn);
                         k = SCSmod0.DataPage_Geometry.aVerticalPlateTopBoltGroup2;
                         OperatewithTekla(0, 1, "rw21", ref k, ref myConn);
                         k = SCSmod0.DataPage_Geometry.aHorintalBeamBoltGroup2;
                         OperatewithTekla(0, 1, "lba2", ref k, ref myConn);
                         k = "0";
                         OperatewithTekla(0, 2, "cut0", ref k, ref myConn);
                         OperatewithTekla(0, 2, "cut2", ref k, ref myConn);
                         OperatewithTekla(0, 2, "btab1", ref k, ref myConn);
                         OperatewithTekla(0, 2, "btab2", ref k, ref myConn);
                         k = "2147483648";
                         OperatewithTekla(0, 2, "atab2", ref k, ref myConn);
                         OperatewithTekla(0, 2, "stagger_type", ref k, ref myConn);
                         OperatewithTekla(0, 1, "stagger_type2", ref k, ref myConn);
                         OperatewithTekla(0, 1, "ctab4", ref k, ref myConn);
                         // plate parameters
                         k = "1";
                         OperatewithTekla(0, 2, "typ", ref k, ref myConn);
                         claDataPage_General.PlateWeldingtoPrimary k8;
                         k8 = SCSmod0.DataPage_General.PlateWeldingtoPrimarySelection;
                         if (k8 != claDataPage_General.PlateWeldingtoPrimary.ThirdOption)
                         {
                            k = SCSmod0.DataPage_Geometry.PlateThicknessBoltGroup2;
                            OperatewithTekla(0, 1, "tpl1", ref k, ref myConn);
                            k = SCSmod0.DataPage_Geometry.PlateDepthBoltGroup2; 
                            OperatewithTekla(0, 1, "bpl1", ref k, ref myConn);
                            k = SCSmod0.DataPage_Geometry.PlateWidthBoltGroup2;
                            OperatewithTekla(0, 1, "hpl1", ref k, ref myConn);
                         }
                         if (k8 != claDataPage_General.PlateWeldingtoPrimary.SecondOption)
                         {
                            k = SCSmod0.DataPage_Geometry.PlateThickness;
                            OperatewithTekla(0, 1, "tpl2", ref k, ref myConn);
                            k = SCSmod0.DataPage_Geometry.PlateDepth;
                            OperatewithTekla(0, 1, "bpl2", ref k, ref myConn);
                            k = SCSmod0.DataPage_Geometry.PlateWidth;
                            OperatewithTekla(0, 1, "hpl2", ref k, ref myConn);
                            if (Convert.ToInt16(SCSmod0.DataPage_PlateandBolts.NumberOfFinPlates) == 2) 
                            {
                               k = "4";
                               OperatewithTekla(0, 2, "typ", ref k, ref myConn);
                               k = SCSmod0.DataPage_Geometry.Splice_InternalFlangePlateThickness;
                               OperatewithTekla(0, 1, "tpl6", ref k, ref myConn);
                               k = SCSmod0.DataPage_Geometry.Splice_InternalFlangePlateDepth;
                               OperatewithTekla(0, 1, "bpl6", ref k, ref myConn);
                               k = SCSmod0.DataPage_Geometry.PlateWidth;
                               OperatewithTekla(0, 1, "hpl6", ref k, ref myConn);
                            }
                         }
                         if (k8 != claDataPage_General.PlateWeldingtoPrimary.FirstOption)
                         {
                            MessageBox.Show("this Tekla connection can only consider both flange and web connected");
                         }
                         break;
                     }
                default:
                     {
                         break;
                     }
            }
         
            try
            {
                if (!myConn.Insert())
                {
                    //MessageBox.Show("Connection Insert failed");
                    myConn.Modify();
                }
                myModel.CommitChanges();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }
            //this.Show();
        }


                private void btnToSCS_Click(object sender, EventArgs e)
        {
            MessageBox.Show("Select Connection in TS 20.0");
            Tekla.Structures.Model.UI.Picker myPicker = new Tekla.Structures.Model.UI.Picker();
            Tekla.Structures.Model.ModelObject myTSObj = default(Tekla.Structures.Model.ModelObject);
            // Selecting connection
            myTSObj = myPicker.PickObject(Tekla.Structures.Model.UI.Picker.PickObjectEnum.PICK_ONE_OBJECT, "Select Connection");
            TSM.Connection myConnection = null;
            if (myTSObj is Tekla.Structures.Model.Connection)
            {
                myConnection = myTSObj as TSM.Connection;
            }
            else
            {
                MessageBox.Show("Select a Connection");
                myTSObj = myPicker.PickObject(Tekla.Structures.Model.UI.Picker.PickObjectEnum.PICK_ONE_OBJECT, "Select Connection");
                if (myTSObj is Tekla.Structures.Model.Connection)
                {
                    myConnection = myTSObj as TSM.Connection;
                }
                else
                {
                    MessageBox.Show("You must select a Connection; operation is aborted");
                    return;  
                }
            }
            OperatewithTekla(1, 1, "diameter", ref k, ref myConnection);
            k =  "M" + k;
            SCSmod0.DataPage_PlateandBolts.BoltSize = k;
            SCSmod0.DataPage_Geometry.CheckBoxStandardBoltSpacing = false;
            SCSmod0.DataPage_Geometry.CheckBoxSymmetricalVerticalBoltinPlate = false;
            SCSmod0.DataPage_Geometry.CheckBoxVerticalSymmetricalBoltinSecondaryMember = false;
            OperatewithTekla(1, 0, "lbd", ref k, ref myConnection);
            SCSmod0.DataPage_Geometry.BoltVerticalPitch = k;
            OperatewithTekla(1, 2, "nb", ref k, ref myConnection);
            SCSmod0.DataPage_Geometry.BoltRows = k;
            OperatewithTekla(1, 1, "rb1", ref k, ref myConnection);
            SCSmod0.DataPage_Geometry.aVerticalBoltPlateTop = k;
            OperatewithTekla(1, 1, "tpl1", ref k, ref myConnection);
            SCSmod0.DataPage_Geometry.PlateThickness = k;
            OperatewithTekla(1, 2, "nw", ref k, ref myConnection);
            if (Convert.ToInt16(k) > 1)
            {
               OperatewithTekla(1, 0, "lwd", ref k1, ref myConnection);
               SCSmod0.DataPage_Geometry.BoltHorizontalGauge = k1;
            }
            OperatewithTekla(1, 1, "lba", ref k, ref myConnection);   
            claDataPage_WeldNotchesandStiffeners.Notch k9;
            k9= SCSmod0.DataPage_WeldNotchStiffeners.NotchSelection;
            if (k9 == claDataPage_WeldNotchesandStiffeners.Notch.NoNotch)
            {
                SCSmod0.DataPage_Geometry.aVertBeamTop = k;
            }
            else
            {
                SCSmod0.DataPage_Geometry.aVertBeamTop = Convert.ToString(Convert.ToDouble(k) - Convert.ToDouble(SCSmod0.DataPage_WeldNotchStiffeners.NotchDepth));
            }
           
            switch (Extn)
            {
                case ".fp1":
                    {
                        OperatewithTekla(1, 1, "rw1", ref k, ref myConnection);
                        OperatewithTekla(1, 1, "dv", ref k1, ref myConnection);
                        k = Convert.ToString(Convert.ToDouble(k) - Convert.ToDouble(k1));
                        SCSmod0.DataPage_Geometry.aHorizBeam = k;
                        SCSmod0.DataPage_Geometry.BeamClearance = k1;
                        OperatewithTekla(1, 1, "rw2", ref k, ref myConnection); 
                        SCSmod0.DataPage_Geometry.aHrizontalPlate = k;
                        OperatewithTekla(1, 2, "nb", ref k, ref myConnection);
                        OperatewithTekla(1, 0, "lbd", ref k1, ref myConnection);
                        w = ((Convert.ToDouble(k)-1) * Convert.ToDouble(k1));
                        OperatewithTekla(1, 1, "rb1", ref k, ref myConnection);
                        OperatewithTekla(1, 1, "hpl1", ref k1, ref myConnection);
                        w = Convert.ToDouble(k1)-Convert.ToDouble(k)-w;
                        SCSmod0.DataPage_Geometry.aVerticalPlateBottom = Convert.ToString(w);
                        break;
                    }
                case ".fp2":
                    {
                        OperatewithTekla(1, 1, "lwa", ref k, ref myConnection); 
                        SCSmod0.DataPage_Geometry.aHorizBeam = k;
                        OperatewithTekla(1, 1, "rw1", ref k, ref myConnection); 
                        SCSmod0.DataPage_Geometry.aHrizontalPlate = k;
                        OperatewithTekla(1, 1, "dv", ref k, ref myConnection);
                        SCSmod0.DataPage_Geometry.BeamClearance = k;
                        OperatewithTekla(1, 1, "tj3", ref k, ref myConnection);
                        SCSmod0.DataPage_WeldNotchStiffeners.PrimaryMemberStiffenerThickness = k;
                        OperatewithTekla(1, 2, "nb", ref k, ref myConnection);
                        OperatewithTekla(1, 0, "lbd", ref k1, ref myConnection);
                        w = ((Convert.ToDouble(k) - 1) * Convert.ToDouble(k1));
                        OperatewithTekla(1, 1, "rb1", ref k, ref myConnection);
                        OperatewithTekla(1, 1, "hpl1", ref k1, ref myConnection);
                        w = Convert.ToDouble(k1) - Convert.ToDouble(k) - w;
                        SCSmod0.DataPage_Geometry.aVerticalPlateBottom = Convert.ToString(w);
                        break;
                    }
                case ".xl1":
                    {
                        OperatewithTekla(1, 1, "hpl1", ref k, ref myConnection);
                        //TEMP SCSmod0.DataPage_Geometry.PlateDepth = k;
                        OperatewithTekla(1, 1, "bpl1", ref k, ref myConnection);
                        SCSmod0.DataPage_Geometry.PlateWidth = k;
                        break;
                    }
                case ".xl2":
                    {
                        OperatewithTekla(1, 1, "rw1", ref k, ref myConnection);
                        OperatewithTekla(1, 1, "rw2", ref k1, ref myConnection);
                        if (k != k1) MessageBox.Show("SCS can't take a different value for rw1 and rw2, conservatively he takes the less of them");
                        w = Convert.ToDouble(k1);
                        if (Convert.ToDouble(k) < Convert.ToDouble(k1))  w = Convert.ToDouble(k);
                        OperatewithTekla(1, 0, "lwd", ref k, ref myConnection);
                        w = 2*w + Convert.ToDouble(k);
                        SCSmod0.DataPage_Geometry.PlateWidth = Convert.ToString(w);
                        OperatewithTekla(1, 2, "nb", ref k, ref myConnection);
                        OperatewithTekla(1, 0, "lbd", ref k1, ref myConnection);
                        w = ((Convert.ToDouble(k) - 1) * Convert.ToDouble(k1));
                        OperatewithTekla(1, 1, "rb1", ref k, ref myConnection);
                        OperatewithTekla(1, 1, "hpl1", ref k1, ref myConnection);
                        w = Convert.ToDouble(k1) - Convert.ToDouble(k) - w;
                        SCSmod0.DataPage_Geometry.aVerticalPlateBottom = Convert.ToString(w);
                        break;
                    }
                case ".sp4": 
                    {
                        OperatewithTekla(1, 2, "nw", ref k, ref myConnection);
                        OperatewithTekla(1, 0, "lwd", ref k1, ref myConnection);
                        k = Convert.ToString((Convert.ToDouble(k)-1) * Convert.ToDouble(k1));
                        OperatewithTekla(1, 1, "bpl2", ref k1, ref myConnection);
                        k = Convert.ToString((Convert.ToDouble(k1) - Convert.ToDouble(k))/2); // real rw1
                        OperatewithTekla(1, 1, "rw1", ref k1, ref myConnection); // fake rw1
                        if (k != k1) MessageBox.Show("please check flange bolt distances with 'b' dimension of flange plate");
                        SCSmod0.DataPage_Geometry.aVerticalBoltPlateTop = k;
                        // //  todo: give "a y beam top" in SCS

                        OperatewithTekla(1, 2, "nw2", ref k, ref myConnection);
                        OperatewithTekla(1, 0, "lwd2", ref k1, ref myConnection);
                        k = Convert.ToString((Convert.ToDouble(k) - 1) * Convert.ToDouble(k1));
                        OperatewithTekla(1, 1, "bpl1", ref k1, ref myConnection); // 
                        k = Convert.ToString((Convert.ToDouble(k1) - Convert.ToDouble(k)) / 2); // real rw21
                        OperatewithTekla(1, 1, "rw21", ref k1, ref myConnection); // fake rw21
                        if (k != k1) MessageBox.Show("please check web bolt distances with 'b' dimension of web plate");
                        SCSmod0.DataPage_Geometry.aVerticalPlateTopBoltGroup2 = k;
                        OperatewithTekla(1, 1, "lba2", ref k, ref myConnection);
                        SCSmod0.DataPage_Geometry.aHorintalBeamBoltGroup2 = k;
                        OperatewithTekla(1, 1, "lba", ref k, ref myConnection);
                        SCSmod0.DataPage_Geometry.aHorizBeam = k;
                        OperatewithTekla(1, 1, "rb21", ref k, ref myConnection);
                        SCSmod0.DataPage_Geometry.aHorizontalPlateBoltGroup2 = k;
                        OperatewithTekla(1, 1, "rb1", ref k, ref myConnection);
                        SCSmod0.DataPage_Geometry.aHrizontalPlate = k;
                        OperatewithTekla(1, 1, "rw1", ref k, ref myConnection);
                        SCSmod0.DataPage_Geometry.aVerticalBoltPlateTop = k;
                        OperatewithTekla(1, 1, "dv", ref k, ref myConnection);
                        SCSmod0.DataPage_Geometry.BeamClearance = k;
                        OperatewithTekla(1, 2, "nb", ref k, ref myConnection);
                        SCSmod0.DataPage_Geometry.BoltColumns = k;
                        OperatewithTekla(1, 2, "nb2", ref k, ref myConnection);
                        SCSmod0.DataPage_Geometry.BoltColumnsBoltGroup2 = k;
                        OperatewithTekla(1, 0, "lbd", ref k, ref myConnection);
                        SCSmod0.DataPage_Geometry.BoltHorizontalGauge = k;
                        OperatewithTekla(1, 0, "lbd2", ref k, ref myConnection);
                        SCSmod0.DataPage_Geometry.BoltHorizontalGaugeBoltGroup2 = k;
                        OperatewithTekla(1, 2, "nw", ref k, ref myConnection);
                        j = (Convert.ToInt16(k) / 2);
                        SCSmod0.DataPage_Geometry.BoltRows = Convert.ToString(j);
                        if (j > 1)
                        {
                           OperatewithTekla(1, 0, "lwd", ref k, ref myConnection);
                           SCSmod0.DataPage_Geometry.BoltVerticalPitch = k;
                        }
                        OperatewithTekla(1, 2, "nw2", ref k, ref myConnection);
                        SCSmod0.DataPage_Geometry.BoltRowsBoltGroup2 = k;
                        OperatewithTekla(1, 0, "lwd2", ref k, ref myConnection);
                        SCSmod0.DataPage_Geometry.BoltVerticalPitchBoltGroup2 = k;
                        OperatewithTekla(1, 1, "tpl1", ref k, ref myConnection);  // web plate
                        SCSmod0.DataPage_Geometry.PlateThicknessBoltGroup2 = k;
                        OperatewithTekla(1, 1, "tpl2", ref k, ref myConnection);  // flange plate
                        SCSmod0.DataPage_Geometry.PlateThickness = k;
                        OperatewithTekla(1, 2, "typ", ref k, ref myConnection);
                        if (k == "2" | k == "4")
                        {
                           k1 = "2";
                           SCSmod0.DataPage_PlateandBolts.NumberOfFinPlates = k1;
                           OperatewithTekla(1, 1, "tpl6", ref k1, ref myConnection);  // internal flange plate
                           SCSmod0.DataPage_Geometry.Splice_InternalFlangePlateThickness = k1;
                        }
                        if (k == "0"  |k == "1" | k == "3")
                        {
                           k1 = "1";
                           SCSmod0.DataPage_PlateandBolts.NumberOfFinPlates = k1;
                        }
                        break;
                   }
            }
            OperatewithTekla(1, 2, "nw", ref k, ref myConnection);
            if (Extn == ".xl2" || Extn == ".xl1" || Extn == ".ap7" || Extn == ".em3")
            {
                if (k != "2" )
                {
                    MessageBox.Show("SCS can only take 2 columns of bolts");
                    k = "2";
                }
            }
            else 
            { 
                if ( Extn != ".sp4"  )  SCSmod0.DataPage_Geometry.BoltColumns = k;
            }
            SCSmod0.OtherControls.Calculate();
        }






        private void OperatewithTekla(int fromSCStoTekla0_fromTeklatoSCS1, int String0Double1Integer2, string TeklaValue, ref string SCSvalue, ref TSM.Connection TeklaConn) 
        {

        if (fromSCStoTekla0_fromTeklatoSCS1 == 0)
        {
            switch (String0Double1Integer2)
            {
                case 0:
                    string SCSValConv = ((string)(SCSvalue));
                    TeklaConn.SetAttribute(TeklaValue, SCSValConv);
                    break;
                case 1:
                    double SCSValdou;
                    double.TryParse(SCSvalue, out SCSValdou);
                    TeklaConn.SetAttribute(TeklaValue, SCSValdou);
                    break;
                case 2:
                    int SCSValInt;
                    int.TryParse(SCSvalue, out SCSValInt);
                    TeklaConn.SetAttribute(TeklaValue, SCSValInt);
                    break;
            }
        }
        else
        {
            switch (String0Double1Integer2)
            {
                case 0:
                      string Temp = "";
                      TeklaConn.GetAttribute(TeklaValue, ref Temp);
                      SCSvalue = Temp;
                      break;
                case 1:
                      double TempD = 0;
                      TeklaConn.GetAttribute(TeklaValue, ref TempD);
                      SCSvalue = Convert.ToString(TempD);
                      break;
                case 2:
                      int TempInt = 0;
                      TeklaConn.GetAttribute(TeklaValue, ref TempInt);
                      SCSvalue = Convert.ToString(TempInt);
                      break;
            }
            
        }
     }

    }
}

  
Import loads from Staad Pro Download code, form included
The same considerations described above (please read) for Sap2000 applies. Don't forget that current version of SCS already has a built in button to import loads from Staad: download the demo and try it out.
Staad Pro steel connections design integration

Option Explicit On
Option Strict Off
'ADD SCS.exe (default location under ...Program Files (x86)\Steel Studio\SCS or equivalent) to your References. SCS.exe (no dll needed) is a .NET type reference. Set 'Copy Local' = True
'In some versions of Visual Studio it might be necessary to set x86 as a target reference to make SCS APIs work
'The macro was tested for Staad.Pro v8i selectseries 5 version  in Visual Studio 2010 (framework 4)
Imports mySCS
Imports STAADLibBentley
Imports System.Math
Imports System.Runtime.InteropServices
Imports System.Runtime.InteropServices.ComTypes

Public Class StaadformMacro
    Inherits System.Windows.Forms.Form
    Private scsObj As mySCS.frmShapedStart
    Private scsModuleGeneric As mySCS.frmFP1 'all modules inherit from type frmFP1 therefore this can point out to any form
    Private WorkingPath As String = IO.Directory.GetParent(IO.Directory.GetParent(Application.StartupPath).FullName.ToString).FullName.ToString & "\Staad Models\"
    Private booFirstTime As Boolean = True
    Private booPrimaryMemberIsaColumn As Boolean = False
    Private booBasePlateJoint As Boolean = False
    Private booBraceJoint As Boolean = False
    Private booSpliceJoint As Boolean = False
    Private formYsize As Integer
    Private tipHowToCreateNewSCSFile As String = "To create a new file use '*'." & vbCrLf & "Example: write *.em3 in the textbox and clicking the 'New' button a new em3 (moment connection) file will be launched."
    Private strReLoadData As String = "remember that if you want to reload data of the selected 'similar' joints, you must re-click the button 'Load Data'"
    Private strNotImportedLoads(4) As String

    Public Sub New()
        ' This call is required by the Windows Form Designer.
        InitializeComponent()
        ' Add any initialization after the InitializeComponent() call.
        formYsize = Me.Size.Height
        Me.Size = New Point(324, formYsize)
        Me.TopMost = True
        btnFormOnTop_Click(btnFormOnTop, New System.EventArgs) 'comment this if you want topmost to true because this command will switch the above command
        strNotImportedLoads(0) = "Remember that SCS does NOT import loads for "
        strNotImportedLoads(1) = " in the selected module: check that restraints in the model are correctly imposed or that values at joints are negligible"
        strNotImportedLoads(2) = strNotImportedLoads(0) & "weak axis moment and torsion" & strNotImportedLoads(1)
        strNotImportedLoads(3) = strNotImportedLoads(0) & "shear (strong and weak axis), torsion and minor moment axis" & strNotImportedLoads(1)
        strNotImportedLoads(3) = strNotImportedLoads(0) & "torsion" & strNotImportedLoads(1)
        ToolTip1.SetToolTip(txbSCSfileName, "choose file name and directory through the button on the right. To create a New (empty) file, just write * and the extension, example (fin plate for column): *.fp1.")
    End Sub
    Private Sub btnSCSopenFile1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSCSopenFile.Click
        CheckifSCSIsOpen()
        Dim fileName As String = txbSCSfileName.Text
        'if the file name is just an asterisk, a new file is created
        If (fileName.Length = 5 AndAlso fileName.Substring(0, 2) = "*.") Or (fileName.Length = 4 AndAlso fileName.Substring(0, 1) = ".") Then
            'If CType(sender, Button).Name = btnSCSopenFile.Name Then
            '    MsgBox("a new file will be created")
            'End If
            Dim extensionString As String = fileName.Substring(fileName.Length - 3, 3)
            scsObj.NewFileAndAssignGenericModuleObject(extensionString, scsModuleGeneric) 'open file directly then, adding the generic module reference will assign the new form to this object 
        Else
            If CType(sender, Button).Name = btnSCSopenFile.Name Then
                scsObj.OpenFileAndAssignGenericModuleObject(WorkingPath & txbSCSfileName.Text, scsModuleGeneric) 'open file directly then, adding the generic module reference will assign the new form to this object 
            Else
                MsgBox(tipHowToCreateNewSCSFile)
            End If
        End If
    End Sub
    Private objOpenSTAAD1 As Object
    Private objOpenSTAAD1viewer As STAADLibBentley.OpenSTAAD
    Private ret As Long
    Private JointData() As JointDataClass
    Private secframeList() As String
    Private jointList() As String
    Private Function CheckIfSCSfileNameIsCompiled(ByVal booDisplayMsg As Boolean) As Boolean
        Dim strWarn As String = "to operate the macro correctly, it's suggested to initially open the module (or at least write the name of the file extension) where you want to export the joints"
        If txbSCSfileName.Text.Length < 4 Then
            If booDisplayMsg Then MsgBox(strWarn)
            Return False
        Else
            Dim SCSfileExtension As String = txbSCSfileName.Text.Substring(txbSCSfileName.Text.Length - 4, 4)
            Select Case SCSfileExtension
                Case Is = ".fp1", ".fp2", ".me0", ".cb8", ".br9", ".em3", ".sp4", ".ds1", ".qs5", ".qs6", ".we1", ".ap7", ".xl1", ".xl2"
                    Return True
                Case Else
                    If booDisplayMsg Then MsgBox("Select valid extension")
                    Return False
            End Select
        End If
    End Function
    Private Sub CheckifStaadIsOpen()
        Try
            If objOpenSTAAD1 Is Nothing Then
                Try
                    objOpenSTAAD1 = GetObject(, "StaadPro.OpenSTAAD")
                Catch ex As Exception
                    MsgBox("Staad must be open, please start Staad")
                    Exit Sub
                End Try
            End If
        Catch ex As Exception
            MsgBox("Staad not available, macro will close")
            Me.Close()
        End Try
    End Sub
    Private Sub CheckifSCSIsOpen()
        If scsObj Is Nothing Then
            scsObj = New mySCS.frmShapedStart
            scsObj.ApplicationStart()
        End If
    End Sub
    Private Function IsBasePlateJoint() As Boolean
        Dim boo As Boolean = False
        Try
            Dim SCSfileExtension As String = txbSCSfileName.Text.Substring(txbSCSfileName.Text.Length - 4, 4)
            If SCSfileExtension.StartsWith(".") Then
                Select Case SCSfileExtension
                    Case Is = ".cb8"
                        Return True
                End Select
            End If
            Return boo
        Catch ex As Exception
            Return False
        End Try
    End Function
    Private Function IsBraceJoint() As Boolean
        Dim boo As Boolean = False
        Try
            Dim SCSfileExtension As String = txbSCSfileName.Text.Substring(txbSCSfileName.Text.Length - 4, 4)
            If SCSfileExtension.StartsWith(".") Then
                Select Case SCSfileExtension
                    Case Is = ".br9"
                        Return True
                End Select
            End If
            Return boo
        Catch ex As Exception
            Return False
        End Try
    End Function
    Private Function IsSpliceJoint() As Boolean
        Dim boo As Boolean = False
        Try
            Dim SCSfileExtension As String = txbSCSfileName.Text.Substring(txbSCSfileName.Text.Length - 4, 4)
            If SCSfileExtension.StartsWith(".") Then
                Select Case SCSfileExtension
                    Case Is = ".sp4"
                        Return True
                End Select
            End If
            Return boo
        Catch ex As Exception
            Return False
        End Try
    End Function
    Private Function IsPrimaryMemeberAColumn() As Boolean
        Dim boo As Boolean = False
        Dim msgtxt As String = "Select SCS file (it's needed to determine primary members) then re-load data"
        If txbSCSfileName.TextLength < 4 Then
            MsgBox(msgtxt)
        Else
            Dim SCSfileExtension As String = txbSCSfileName.Text.Substring(txbSCSfileName.Text.Length - 4, 4)
            If SCSfileExtension.StartsWith(".") Then
                Select Case SCSfileExtension
                    Case Is = ".fp1", ".xl1", ".qs5", ".em3", ".we1"
                        Return True
                End Select
            Else
                MsgBox(msgtxt)
            End If
        End If
        Return boo
    End Function
    Private errorMsgCountSec As Integer = 0
    Private errorMsgCountJoints As Integer = 0
    Private booMsgSelectSecAndJointsDisplayedAlready As Boolean = False
    Private booMsgReloadDataDisplayedAlready As Boolean = False
    Private Sub CompileWarning()
        Dim SCSfileExtension As String = txbSCSfileName.Text.Substring(txbSCSfileName.Text.Length - 4, 4)
        If SCSfileExtension.StartsWith(".") Then
            Select Case SCSfileExtension
                Case Is = ".br9"
                    lblWarningForLoadsNotImported.Text = strNotImportedLoads(3)
                Case Is = ".qs5", ".qs6", ".xl1", ".xl2", ".fp1", ".fp2", ".ds1"
                    lblWarningForLoadsNotImported.Text = strNotImportedLoads(3)
                Case Is = ".sp4"
                    lblWarningForLoadsNotImported.Text = strNotImportedLoads(4)
                Case Else
                    lblWarningForLoadsNotImported.Text = Nothing
            End Select
        End If
    End Sub
    Private Sub btnDoStuff_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnDoStuff.Click
        CheckifStaadIsOpen()
        If CheckIfSCSfileNameIsCompiled(True) = False Then Exit Sub
        lblSelJointsStrings.Text = Nothing
        lblSecMemberProperty.Text = Nothing
        cobPrimaryMember.Items.Clear()
        booPrimaryMemberIsaColumn = IsPrimaryMemeberAColumn()
        booBasePlateJoint = IsBasePlateJoint()
        booBraceJoint = IsBraceJoint()
        booSpliceJoint = IsSpliceJoint()
        CompileWarning()

        If booBasePlateJoint Then
            btnPrimMembShow.Visible = False
            lblPrimaryMember.Visible = False
            cobPrimaryMember.Visible = False
        Else
            btnPrimMembShow.Visible = True
            lblPrimaryMember.Visible = True
            cobPrimaryMember.Visible = True
        End If

        If booMsgSelectSecAndJointsDisplayedAlready = False Then
            MsgBox("Go to the open Staad model: select SECONDARY members AND JOINTS you want loads from THEN click OK", MsgBoxStyle.OkOnly)
            booMsgSelectSecAndJointsDisplayedAlready = True
            Exit Sub
        End If

        Dim strSelectedPoints As String = Nothing
        ReDim jointList(0)
        Dim NumberOfJoints As Integer = 0
        Dim NumberOfSecondaryMembers As Integer = 0
        NumberOfSecondaryMembers = objOpenSTAAD1.Geometry.GetNoOfSelectedBeams
        NumberOfJoints = objOpenSTAAD1.Geometry.GetNoOfSelectedNodes

        If NumberOfSecondaryMembers = 0 Then
            If errorMsgCountSec < 2 Then
                MsgBox("no secondary member selected, go to Staad and modify selection")
                errorMsgCountSec += 1
                btnDoStuff_Click(sender, e)
            End If
            Exit Sub
        End If
        If NumberOfJoints = 0 Then
            If errorMsgCountJoints < 2 Then
                MsgBox("no joints selected, go to Staad and modify selection")
                errorMsgCountJoints += 1
                btnDoStuff_Click(sender, e)
            End If
            Exit Sub
        End If
        Dim selNodes(NumberOfJoints - 1) As Integer
        objOpenSTAAD1.Geometry.GetSelectedNodes(selNodes, 1)
        For i = 0 To NumberOfJoints - 1
            ReDim Preserve jointList(i)
            jointList(i) = selNodes(i)
            strSelectedPoints += jointList(i) + ", "
        Next
        Dim selSec(NumberOfSecondaryMembers - 1) As Integer
        objOpenSTAAD1.Geometry.GetSelectedBeams(selSec, 1)
        For i = 0 To NumberOfSecondaryMembers - 1
            ReDim Preserve secframeList(i)
            secframeList(i) = selSec(i)
        Next
        lblSelJointsStrings.Text = strSelectedPoints

        Dim JointArrayMaxIndex As Integer = Max(0, NumberOfJoints - 1)
        ReDim JointData(JointArrayMaxIndex)
        Dim BeamList() As Integer
        Dim ObjectName() As String
        Dim DataB_ObjName(JointArrayMaxIndex, 0) As String
        Dim DataB_PropertyName(JointArrayMaxIndex, 0) As String
        Dim PropName As String = Nothing
        Dim Members As New List(Of String)
        Dim S33 As Double
        Dim Point1 As String
        Dim Point2 As String
        Dim x As Double, y As Double, z As Double
        Dim x2 As Double, y2 As Double, z2 As Double

        PropName = objOpenSTAAD1.Property.GetBeamSectionName(secframeList(0))
        If NumberOfSecondaryMembers > 1 Then
            Dim PropName2 As String
            For k = 1 To NumberOfSecondaryMembers - 1
                PropName2 = objOpenSTAAD1.Property.GetBeamSectionName(secframeList(k))
                If PropName2 <> PropName Then
                    MsgBox("secondary members must have the same section property, go to Staad and modify selection")
                    btnDoStuff_Click(sender, e)
                    Exit Sub
                End If
            Next
        End If
        lblSecMemberProperty.Text = PropName

        Dim listofConnectingMembersByJoint(JointArrayMaxIndex) As List(Of Integer)
        For p = 0 To JointArrayMaxIndex
            listofConnectingMembersByJoint(p) = New List(Of Integer)
        Next
        Dim dimbeaArray As Integer = objOpenSTAAD1.geometry.GetMemberCount - 1
        Dim beamArray(dimbeaArray) As Integer
        ret = objOpenSTAAD1.Geometry.GetBeamList(beamArray)
        Dim val1 As Integer = 0
        Dim val2 As Integer = 0
        Dim booFound1, booFound2 As Boolean
        For r = 0 To dimbeaArray
            ret = objOpenSTAAD1.Geometry.GetMemberIncidence(beamArray(r), val1, val2)
            booFound1 = False
            booFound2 = False
            For k = 0 To JointArrayMaxIndex
                If Not booFound1 AndAlso val1 = CInt(jointList(k)) Then
                    listofConnectingMembersByJoint(k).Add(beamArray(r))
                    booFound1 = True
                End If
                If Not booFound2 AndAlso val2 = CInt(jointList(k)) Then
                    listofConnectingMembersByJoint(k).Add(beamArray(r))
                    booFound2 = True
                End If
            Next
        Next

        For k = 0 To JointArrayMaxIndex
            Dim NumberOfConnectedMembers As Integer = listofConnectingMembersByJoint(k).Count
            ReDim BeamList(NumberOfConnectedMembers - 1)
            For q = 0 To NumberOfConnectedMembers - 1
                BeamList(q) = listofConnectingMembersByJoint(k).Item(q)
            Next
            ReDim ObjectName(NumberOfConnectedMembers - 1)
            JointData(k) = New JointDataClass(NumberOfConnectedMembers)
            JointData(k).PrimaryMemberIsaColumn = booPrimaryMemberIsaColumn
            JointData(k).BasePlateJoint = booBasePlateJoint
            JointData(k).BraceJoint = booBraceJoint
            JointData(k).SpliceJoint = booSpliceJoint
            JointData(k).Label = jointList(k)

            Dim maxExt As Integer = NumberOfConnectedMembers - 1
            ReDim Preserve DataB_ObjName(JointArrayMaxIndex, maxExt)
            ReDim Preserve DataB_PropertyName(JointArrayMaxIndex, maxExt)

            For q = 0 To NumberOfConnectedMembers - 1
                DataB_ObjName(k, q) = BeamList(q)
                PropName = objOpenSTAAD1.Property.GetBeamSectionName(BeamList(q))
                Dim PropNameRefNumber As Integer = objOpenSTAAD1.property.GetBeamSectionPropertyTypeNo(BeamList(q))
                Dim dWidth, dDepth, dAx, Day, dAz, dIx, dIy, dIz As Double
                objOpenSTAAD1.Property.GetBeamProperty(BeamList(q), dWidth, dDepth, dAx, Day, dAz, dIx, dIy, dIz)
                S33 = dIy
                DataB_PropertyName(k, q) = PropName
                JointData(k).GuessedPrimaryMember_property_OverWrite = False
                JointData(k).PropertyName(q) = PropName
                ObjectName(q) = BeamList(q)
                JointData(k).ObjName(q) = ObjectName(q) 'this is the analysis label, example 36-2 ACTUALLY IN STAAD IS ONLY 36 as ObjNameRoot below
                JointData(k).PropertyRefValue(q) = S33
                JointData(k).GuessedSecondaryMember_property = PropName
                Members.Add(PropName)
                JointData(k).GetObjNameRoot(q) 'this is the model label, example 36
                objOpenSTAAD1.Geometry.GetMemberIncidence(BeamList(q), val1, val2)
                Point1 = val1.ToString
                Point2 = val2.ToString
                If Point1 = jointList(k) Then
                    JointData(k).ObjNode(q) = 0
                Else
                    JointData(k).ObjNode(q) = 1
                End If
                ReDim Preserve JointData(k).FrameElements(q)
                ret = objOpenSTAAD1.Geometry.GetNodeCoordinates(val1, x, z, y) 'in the macro, z is vertical, in staad y is vertical
                ret = objOpenSTAAD1.Geometry.GetNodeCoordinates(val2, x2, z2, y2)
                Dim co1() As Double = {x, y, z}
                Dim co2() As Double = {x2, y2, z2}
                JointData(k).FrameElements(q) = New FrameElement(JointData(k).ObjectNameRoot(q), co1, co2) 'this is the model label, example 36
            Next
            JointData(k).GuessPrimaryMembersAndAssignSecMembers(secframeList)
        Next

        If JointArrayMaxIndex > 0 Then
            For uu = 1 To JointArrayMaxIndex
                For jjjj = 0 To uu - 1
                    If JointData(jjjj).GuessedPrimaryMember_property <> JointData(uu).GuessedPrimaryMember_property Then
                        If JointData(jjjj).GuessedPrimaryMember_Name IsNot Nothing And JointData(jjjj).GuessedPrimaryMember_Name IsNot Nothing Then
                            MsgBox("problem with primary members, it seems members with labels " & JointData(jjjj).GuessedPrimaryMember_Name & " and " & JointData(uu).GuessedPrimaryMember_Name & " have different properties, please check")
                        Else
                            MsgBox("problem with primary members, it seems some members have different properties, please check")
                        End If
                        Exit For
                    End If
                Next
            Next
        End If

        If booFirstTime Then
            Me.Size = New Point(924, formYsize)
            cobFilter.SelectedIndex = 0
            lblWarning.Text = ""
        End If

        Dim MembersDistinctList As New List(Of String)
        MembersDistinctList = FindDistinctValues(Members)
        For r = 0 To MembersDistinctList.Count - 1
            cobPrimaryMember.Items.Add(MembersDistinctList.Item(r))
        Next
        AssignComboBoxValue(cobPrimaryMember, JointData(0).GuessedPrimaryMember_property)

        MemorizeListBoxSelection()
        ComboDictionary.Clear()
        lbxLoads.Items.Clear()
        Dim booUsePrimaryLoadCasesInsteadOfCombos As Boolean = False
        Dim numberofCombos As Integer = objOpenSTAAD1.Load.GetLoadCombinationCaseCount
        If numberofCombos = 0 Then
            booUsePrimaryLoadCasesInsteadOfCombos = True
            numberofCombos = objOpenSTAAD1.Load.GetPrimaryLoadCaseCount
        End If
        Dim CombosNumbers(numberofCombos - 1) As Integer
        Dim MyName(numberofCombos - 1) As String
        If booUsePrimaryLoadCasesInsteadOfCombos Then
            objOpenSTAAD1.Load.GetPrimaryLoadCaseNumbers(CombosNumbers)
        Else
            objOpenSTAAD1.Load.GetLoadCombinationCaseNumbers(CombosNumbers)
        End If
        For qq = 0 To numberofCombos - 1
            MyName(qq) = objOpenSTAAD1.Load.GetLoadCaseTitle(CombosNumbers(qq))
            lbxLoads.Items.Add(MyName(qq))
            ComboDictionary.Add(MyName(qq), CombosNumbers(qq))
        Next
        If LoadCasesSelected.Count > 0 Then '141127 revision to reselect previous load cases after data are reloaded
            For ww = 0 To LoadCasesSelected.Count - 1
                For i = 0 To lbxLoads.Items.Count - 1
                    If lbxLoads.Items(i).ToString = LoadCasesSelected(ww) Then
                        lbxLoads.SetSelected(i, True)
                        Exit For
                    End If
                Next
            Next
        End If
        errorMsgCountSec = 0
        errorMsgCountJoints = 0
        booFirstTime = False
    End Sub
    Private ComboDictionary As New Dictionary(Of String, Integer)
    Public Sub ExportResults(ByVal LoadCases As String())
        If LoadCases.Count = 0 Then
            MsgBox("select load cases")
            Exit Sub
        End If
        Dim UnitForce As String
        Dim UnitForceInt As Integer = objOpenSTAAD1.output.GetOutputUnitForForce 'FROM tests, it seems just 3 comes out and it's always in KN. User to check if this applies to their system
        Dim UnitForceInput As Integer = objOpenSTAAD1.GetInputUnitForForce()
        If UnitForceInt = 3 Then
            UnitForce = "KN"
        Else
            MsgBox("set up units for force in VB before proceeding")
            Exit Sub
        End If
        Dim UnitMoment As String
        Dim UnitMomentInt As Integer = objOpenSTAAD1.output.GetOutputUnitForMoment 'FROM tests, it seems just 4 comes out and it's always in KN*m. User to check if this applies to their system
        Dim UnitLengthInput As Integer = objOpenSTAAD1.GetInputUnitForLength()
        If UnitMomentInt = 4 Then
            UnitMoment = "kN*m"
        Else
            MsgBox("set up units for Moment in VB before proceeding")
            Exit Sub
        End If
        Dim multiplierForce As Double = 1
        Dim multiplierMoment As Double = 1
        Dim roundingfiguresForce As Integer = 2
        Dim roundingfiguresMoment As Integer = 2
        Dim F1ta() As Double
        Dim F2ta() As Double
        Dim F3ta() As Double
        Dim JM1ta() As Double
        Dim JM2ta() As Double
        Dim JM3ta() As Double
        Dim FrameLabel As String
        Dim LCname() As String
        Dim Pf(), V2f(), V3f(), M2f(), M3f(), Tf() As Double
        Dim Pftemp(), V2ftemp(), V3ftemp(), M2ftemp(), M3ftemp(), Tftemp() As Double
        Dim totalCasestoExport As Integer
        Dim ForceArray(LoadCasesSelected.Count - 1, 5) As Double
        For x = 0 To JointData.Length - 1
            If booBasePlateJoint Then
                Dim JointLabel As String
                JointLabel = JointData(x).Label
                Dim lNode As Integer = JointLabel
                Dim lLoadCase As Integer
                For y As Integer = 0 To LoadCasesSelected.Count - 1
                    lLoadCase = ComboDictionary.Item(LoadCasesSelected(y).ToString)
                    Dim dReactionArray(5) As Double
                    'Dim sras As Integer
                    Try
                        objOpenSTAAD1.Output.GetSupportReactions(lNode, lLoadCase, dReactionArray)
                    Catch ex As Exception
                        MsgBox("Error. Are results available in the model? did you run analysis?")
                        Exit Sub
                    End Try
                    For www = 0 To 5
                        ForceArray(y, www) = dReactionArray(www)
                    Next
                Next
                Dim Ang As Double = 0
                'to adjust if local axis of member is rotated
                Ang = objOpenSTAAD1.Property.GetBetaAngle(JointData(x).GuessedSecondaryMember_Name(0))
                Ang = Ang / 180 * PI
                totalCasestoExport = LoadCasesSelected.Count
                ReDim Pf(totalCasestoExport - 1)
                ReDim V2f(totalCasestoExport - 1)
                ReDim V3f(totalCasestoExport - 1)
                ReDim M2f(totalCasestoExport - 1)
                ReDim M3f(totalCasestoExport - 1)
                ReDim Tf(totalCasestoExport - 1)
                ReDim LCname(totalCasestoExport - 1)
                ReDim Pftemp(totalCasestoExport - 1)
                ReDim V2ftemp(totalCasestoExport - 1)
                ReDim V3ftemp(totalCasestoExport - 1)
                ReDim M2ftemp(totalCasestoExport - 1)
                ReDim M3ftemp(totalCasestoExport - 1)
                ReDim Tftemp(totalCasestoExport - 1)
                ReDim F1ta(totalCasestoExport - 1)
                ReDim F2ta(totalCasestoExport - 1)
                ReDim F3ta(totalCasestoExport - 1)
                ReDim JM1ta(totalCasestoExport - 1)
                ReDim JM2ta(totalCasestoExport - 1)
                ReDim JM3ta(totalCasestoExport - 1)
                For w = 0 To totalCasestoExport - 1
                    F1ta(w) = -ForceArray(w, 0)
                    F2ta(w) = -ForceArray(w, 2) '-z in staad is +y in a tern with z vertical as considerd in the macro
                    F3ta(w) = ForceArray(w, 1)
                    JM1ta(w) = ForceArray(w, 3)
                    JM2ta(w) = -ForceArray(w, 5)
                    JM3ta(w) = ForceArray(w, 4)

                    Select Case JointData(x).FrameElements(JointData(x).GuessedSecondaryMember_index(0)).MainDirectionZvertical_0x_1y_2z_3xyPlane_4xzplane_5yzplane_6xyz
                        Case Is = 0
                            Pftemp(w) = -F1ta(w) 'axial
                            V2ftemp(w) = F2ta(w) * Cos(Ang) - F3ta(w) * Sin(Ang) 'major axis
                            V3ftemp(w) = F2ta(w) * Sin(Ang) + F3ta(w) * Cos(Ang)
                            Tftemp(w) = JM1ta(w)
                            M2ftemp(w) = JM2ta(w) * Cos(Ang) - JM3ta(w) * Sin(Ang)
                            M3ftemp(w) = JM2ta(w) * Sin(Ang) + JM3ta(w) * Cos(Ang)
                        Case Is = 1
                            Pftemp(w) = -F2ta(w)
                            V2ftemp(w) = F3ta(w) * Cos(Ang) - F1ta(w) * Sin(Ang)
                            V3ftemp(w) = F3ta(w) * Sin(Ang) + F1ta(w) * Cos(Ang)
                            Tftemp(w) = JM2ta(w)
                            M2ftemp(w) = JM3ta(w) * Cos(Ang) - JM1ta(w) * Sin(Ang)
                            M3ftemp(w) = JM3ta(w) * Sin(Ang) + JM1ta(w) * Cos(Ang)
                        Case Is = 2
                            Pftemp(w) = -F3ta(w)
                            V2ftemp(w) = F1ta(w) * Cos(Ang) - F2ta(w) * Sin(Ang)
                            V3ftemp(w) = F1ta(w) * Sin(Ang) + F2ta(w) * Cos(Ang)
                            Tftemp(w) = JM3ta(w)
                            M2ftemp(w) = JM1ta(w) * Cos(Ang) - JM2ta(w) * Sin(Ang)
                            M3ftemp(w) = JM1ta(w) * Sin(Ang) + JM2ta(w) * Cos(Ang)
                        Case Else
                            If w = 0 Then MsgBox("check how to distribute correctly loads along member axes")
                            'formulas belew are not ok, just general reference, MANUAL modification necessary
                            Pftemp(w) = -F2ta(w)
                            V2ftemp(w) = F1ta(w)
                            V3ftemp(w) = F3ta(w)
                            Tftemp(w) = JM2ta(w)
                            M2ftemp(w) = JM1ta(w)
                            M3ftemp(w) = JM3ta(w)
                    End Select
                    LCname(w) = LoadCasesSelected(w)
                    Pf(w) = CheckMostStressingValue(Pf(w), Pftemp(w))
                    V2f(w) = CheckMostStressingValue(V2f(w), V2ftemp(w))
                    V3f(w) = CheckMostStressingValue(V3f(w), V3ftemp(w))
                    M2f(w) = CheckMostStressingValue(M2f(w), M2ftemp(w))
                    M3f(w) = CheckMostStressingValue(M3f(w), M3ftemp(w))
                    Tf(w) = CheckMostStressingValue(Tf(w), Tftemp(w))
                Next
            Else
                For xx = 0 To JointData(x).GuessedSecondaryMember_Name.Length - 1
                    FrameLabel = JointData(x).GuessedSecondaryMember_Name(xx)
                    Dim lMemberNo As Integer = FrameLabel
                    Dim lEnd As Integer = JointData(x).ObjNode(JointData(x).GuessedSecondaryMember_index(xx))
                    Dim lLoadCase As Integer
                    For y As Integer = 0 To LoadCasesSelected.Count - 1
                        lLoadCase = ComboDictionary.Item(LoadCasesSelected(y).ToString)
                        Dim dForceArray(5) As Double
                        'Dim sras As Integer
                        Try
                            objOpenSTAAD1.Output.GetMemberEndForces(lMemberNo, lEnd, lLoadCase, dForceArray)
                        Catch ex As Exception
                            MsgBox("Error. Are results available in the model? did you run analysis?")
                            Exit Sub
                        End Try
                        For www = 0 To 5
                            ForceArray(y, www) = dForceArray(www)
                        Next
                    Next
                    If x = 0 And xx = 0 Then
                        totalCasestoExport = LoadCasesSelected.Count
                        ReDim Pf(totalCasestoExport - 1)
                        ReDim V2f(totalCasestoExport - 1)
                        ReDim V3f(totalCasestoExport - 1)
                        ReDim M2f(totalCasestoExport - 1)
                        ReDim M3f(totalCasestoExport - 1)
                        ReDim Tf(totalCasestoExport - 1)
                        ReDim LCname(totalCasestoExport - 1)
                    End If
                    ReDim Pftemp(totalCasestoExport - 1)
                    ReDim V2ftemp(totalCasestoExport - 1)
                    ReDim V3ftemp(totalCasestoExport - 1)
                    ReDim M2ftemp(totalCasestoExport - 1)
                    ReDim M3ftemp(totalCasestoExport - 1)
                    ReDim Tftemp(totalCasestoExport - 1)
                    For w = 0 To totalCasestoExport - 1
                        'note that in staad P positive means compression, P negative means tension, opposite of SCS; though, in Staad the FX value at the second node (lend=1) of the member is opposite in sign to the first node
                        If lEnd = 0 Then
                            Pftemp(w) = -ForceArray(w, 0)
                        Else 'lend=1
                            Pftemp(w) = ForceArray(w, 0)
                        End If
                        V2ftemp(w) = ForceArray(w, 1) 'major axis
                        V3ftemp(w) = ForceArray(w, 2)
                        M2ftemp(w) = ForceArray(w, 4)
                        M3ftemp(w) = ForceArray(w, 5) 'major axis
                        Tftemp(w) = ForceArray(w, 3)
                        LCname(w) = LoadCasesSelected(w)
                        Pf(w) = CheckMostStressingValue(Pf(w), Pftemp(w))
                        V2f(w) = CheckMostStressingValue(V2f(w), V2ftemp(w))
                        V3f(w) = CheckMostStressingValue(V3f(w), V3ftemp(w))
                        M2f(w) = CheckMostStressingValue(M2f(w), M2ftemp(w))
                        M3f(w) = CheckMostStressingValue(M3f(w), M3ftemp(w))
                        Tf(w) = CheckMostStressingValue(Tf(w), Tftemp(w))
                    Next
                Next
            End If
        Next

        If scsModuleGeneric Is Nothing Then
            btnSCSopenFile1_Click(btnSCSopenFile, New System.EventArgs)
        End If
        Try
            Dim SecMemberName As String = ChangeNameForHE(lblSecMemberProperty.Text)
            Dim PrimMemberName As String = ChangeNameForHE(cobPrimaryMember.SelectedItem.ToString)
            scsModuleGeneric.DataPage_Members.SecondaryMemberSection = SecMemberName
            If booBasePlateJoint = False And booSpliceJoint = False Then scsModuleGeneric.DataPage_Members.PrimaryMemberSection = PrimMemberName
            Select Case UnitForce
                Case Is = "lb"
                    scsModuleGeneric.FormUnits.ForceUnit = "lbf"
                    roundingfiguresForce = 0
                Case Is = "Kip", "kip"
                    scsModuleGeneric.FormUnits.ForceUnit = "kips"
                    roundingfiguresForce = 2
                Case Is = "KN", "kN"
                    scsModuleGeneric.FormUnits.ForceUnit = "kN"
                    roundingfiguresForce = 2
                Case Is = "N"
                    scsModuleGeneric.FormUnits.ForceUnit = "N"
                    roundingfiguresForce = 0
                Case Is = "Tonf", "Ton", "ton", "tons"
                    scsModuleGeneric.FormUnits.ForceUnit = "kN"
                    roundingfiguresForce = 2
                    multiplierForce = 10
                Case Is = "Kgf", "kgf"
                    scsModuleGeneric.FormUnits.ForceUnit = "kg"
                    roundingfiguresForce = 0
            End Select
            Select Case UnitMoment
                Case Is = "KNm", "kNm", "kN*m", "KN*M", "KNM", "KN*m"
                    scsModuleGeneric.FormUnits.MomentUnit = "kN*m"
                    roundingfiguresForce = 2
                    'SET UP OTHER CASES
            End Select
            For w = 0 To totalCasestoExport - 1
                If w > 9 Then
                    MsgBox("Results are more than 10 arrays and import is stopped to 10. You could set up a routine in the macro to find most stressful cases or import in more files.")
                    Exit For
                End If
                scsModuleGeneric.DataPage_Loads.AxialForce(w) = Round(Pf(w) * multiplierForce, roundingfiguresForce).ToString
                If booBraceJoint = False Then
                    scsModuleGeneric.DataPage_Loads.ShearForceMajorAxis(w) = Round(V2f(w) * multiplierForce, roundingfiguresForce).ToString
                    scsModuleGeneric.DataPage_Loads.ShearForceMinorAxis(w) = Round(V3f(w) * multiplierForce, roundingfiguresForce).ToString
                End If
                scsModuleGeneric.DataPage_Loads.MomentMajorAxis(w) = Round(M3f(w) * multiplierMoment, roundingfiguresMoment).ToString
                'CAREFUL, MOMENT WEAK AXIS AND TORSION ARE NOT CALCULATED IN SOME SCS MODULES, MAKE SURE YOUR RESTRAINTS IN THE MODEL TAKE THIS INTO CONSIDERATION (hinges where necessary for pin type connections)
                If scsModuleGeneric.DataPage_Loads.IsLoadApplicable(claDataPage_Loads.LoadType.MomentMinorAxis) Then scsModuleGeneric.DataPage_Loads.MomentMinorAxis(w) = (Round(M2f(w) * multiplierMoment, roundingfiguresMoment)).ToString
                If scsModuleGeneric.DataPage_Loads.IsLoadApplicable(claDataPage_Loads.LoadType.Torsion) Then scsModuleGeneric.DataPage_Loads.Torsion(w) = (Round(Tf(w) * multiplierMoment, roundingfiguresMoment)).ToString
                scsModuleGeneric.DataPage_Loads.CaseName(w) = LCname(w)
            Next
            scsModuleGeneric.OtherControls.Calculate()
            MsgBox("done")
        Catch ex As Exception
            MsgBox("Error in exporting members")
        End Try
    End Sub
    Private Function ChangeNameForHE(ByVal strR As String) As String
        If strR.StartsWith("HE") Then
            Dim NameMovingtheLetterToFront As String
            NameMovingtheLetterToFront = strR.Substring(0, 2) & strR.Substring(strR.Length - 1, 1) & strR.Substring(2, strR.Length - 3)
            Return NameMovingtheLetterToFront
        ElseIf strR.StartsWith("IS") AndAlso strR.Substring(3, 1) = "B" Then
            Dim NameAddSpace As String
            NameAddSpace = strR.Substring(0, 4) & " " & strR.Substring(4, strR.Length - 4)
            Return NameAddSpace
        Else
            Return strR
        End If
    End Function
    Private Function CheckMostStressingValue(ByVal vl1 As Double, ByVal vl2 As Double) As Double
        If Abs(vl1) > Abs(vl2) Then
            Return vl1
        Else
            Return vl2
        End If
    End Function
    Public Sub AssignComboBoxValue(ByRef cob As ComboBox, ByVal stringa As String)
        For i = 0 To cob.Items.Count - 1
            If cob.Items(i).ToString = stringa Then
                cob.SelectedIndex = i
                Exit For
            End If
        Next
    End Sub
    Public Function FindDistinctValues(ByVal ListaStart As List(Of String)) As List(Of String)
        Dim itemsToRemove As New List(Of Integer)
        For j = 1 To ListaStart.Count - 1
            For jj = 0 To j - 1
                If ListaStart.Item(j) = ListaStart.Item(jj) Then
                    itemsToRemove.Add(j)
                    Exit For
                End If
            Next
        Next
        If itemsToRemove.Count > 0 Then
            For i = itemsToRemove.Count - 1 To 0 Step -1
                ListaStart.RemoveAt(itemsToRemove.Item(i))
            Next
        End If
        Return ListaStart
    End Function
    Public Sub ShowMembers(ByVal _1primary_2secondary As Integer)
        If _1primary_2secondary = 1 Or _1primary_2secondary = 2 Then
            Dim target As String
            CheckifStaadIsOpen()
            If JointData IsNot Nothing Then
                ret = objOpenSTAAD1.Geometry.clearnodeselection
                ret = objOpenSTAAD1.Geometry.clearmemberselection
                For j = 0 To jointList.Count - 1
                    ret = objOpenSTAAD1.Geometry.selectnode(jointList(j))
                Next
                For j = 0 To JointData.Count - 1
                    For jj = 0 To JointData(j).ObjectCount - 1
                        If _1primary_2secondary = 1 Then
                            target = JointData(j).GuessedPrimaryMember_property
                        Else
                            target = JointData(j).GuessedSecondaryMember_property
                        End If
                        If JointData(j).PropertyName(jj) = target Then
                            ret = objOpenSTAAD1.Geometry.selectbeam(JointData(j).ObjectNameRoot(jj))
                        End If
                    Next
                Next
            End If
        End If
    End Sub
    Private strWarning As String = "You cannot choose more than 10 cases"
    Private Sub btnSecMembShow_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSecMembShow.Click
        ShowMembers(2)
    End Sub
    Private Sub btnPrimMembShow_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnPrimMembShow.Click
        ShowMembers(1)
    End Sub
    Private Sub cobPrimaryMember_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cobPrimaryMember.SelectedIndexChanged
        For Each item In JointData
            item.GuessedPrimaryMember_property_OverWrite = True
            item.GuessedPrimaryMember_property = cobPrimaryMember.SelectedItem
        Next
    End Sub
    Private LoadCasesSelected As String()
    Private Sub btnExportToSCS_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnExportToSCS.Click
        MemorizeListBoxSelection()
        ExportResults(LoadCasesSelected)
        Personalization()
    End Sub
    Private Sub Personalization()
    End Sub
    Private Sub MemorizeListBoxSelection()
        Dim value As ListBox.SelectedObjectCollection
        value = lbxLoads.SelectedItems
        Dim totalnumber As Integer = value.Count
        If totalnumber > 10 Then
            lblWarning.Text = strWarning & ", only first 10 cases will be exported"
        Else
            lblWarning.Text = ""
        End If
        ReDim LoadCasesSelected(totalnumber - 1)
        For i = 0 To Min(10, totalnumber - 1)
            LoadCasesSelected(i) = value(i).ToString
        Next
    End Sub
    Private Sub btnFilter_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnFilter.Click
        Dim stringToLookFor As String = txbFilter.Text
        If chbFilter.Checked = False Then lbxLoads.ClearSelected()
        Dim booIgnoreCase As Boolean = Not chbCaseSensitive.Checked
        Dim coun As Integer = 0
        Dim strComp As System.StringComparison = StringComparison.CurrentCultureIgnoreCase
        If chbCaseSensitive.Checked Then strComp = StringComparison.CurrentCulture
        For i = 0 To lbxLoads.Items.Count - 1
            Select Case cobFilter.SelectedIndex
                Case Is = 0
                    If lbxLoads.Items(i).ToString.StartsWith(stringToLookFor, booIgnoreCase, Nothing) Then
                        lbxLoads.SetSelected(i, True)
                        coun += 1
                    End If
                Case Is = 1
                    If lbxLoads.Items(i).ToString.IndexOf(stringToLookFor, 0, strComp) > -1 Then
                        lbxLoads.SetSelected(i, True)
                        coun += 1
                    End If
            End Select
        Next
        If coun > 10 Then
            lblWarning.Text = strWarning
        Else
            lblWarning.Text = ""
        End If
    End Sub
    Private Sub btnExitSCS_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnExitSCS.Click
        scsModuleGeneric.Close()
        scsModuleGeneric = Nothing
    End Sub
    Private Sub btnFormOnTop_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnFormOnTop.Click
        If Me.TopMost Then
            Me.TopMost = False
            btnFormOnTop.Text = "Keep form on top of others"
        Else
            Me.TopMost = True
            btnFormOnTop.Text = "Don't keep form on top of others"
        End If
    End Sub
    Private Sub btnFindSimilar_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnFindSimilar.Click
        If CheckIfSCSfileNameIsCompiled(True) = False Then Exit Sub
        lblVisualCheck.Visible = True
        Dim PropName As String = Nothing
        Dim SecProp As String = lblSecMemberProperty.Text
        Dim PrimProp As String = cobPrimaryMember.SelectedItem.ToString
        Dim dimbeaArray As Integer = objOpenSTAAD1.geometry.GetMemberCount - 1
        Dim beamArray(dimbeaArray) As Integer
        Dim dimsuppArray As Integer = objOpenSTAAD1.support.GetSupportCount - 1
        Dim supportArray(dimsuppArray) As Integer
        ret = objOpenSTAAD1.Geometry.GetBeamList(beamArray)
        Dim ListSecMemb As New List(Of Integer)
        Dim ListSecMembTemp As New List(Of Integer)
        Dim ListSecJoints As New List(Of Integer)
        Dim ListPrimMemb As New List(Of Integer)
        Dim ListPrimJoints As New List(Of Integer)
        Dim val1 As Integer = 0
        Dim val2 As Integer = 0
        Dim booSamePropertyForPrimAndSec As Boolean = False
        Dim booMessageSamePropDisplayed As Boolean = False
        booBasePlateJoint = IsBasePlateJoint()
        booBraceJoint = IsBraceJoint()
        booSpliceJoint = IsSpliceJoint()
        If SecProp = PrimProp Then booSamePropertyForPrimAndSec = True
        For r = 0 To dimbeaArray
            PropName = objOpenSTAAD1.Property.GetBeamSectionName(beamArray(r))
            If PropName = SecProp Then
                If booSamePropertyForPrimAndSec Or booSpliceJoint Then
                    ListSecMembTemp.Add(beamArray(r))
                Else
                    ListSecMemb.Add(beamArray(r))
                End If
                ret = objOpenSTAAD1.Geometry.GetMemberIncidence(beamArray(r), val1, val2)
                ListSecJoints.Add(val1)
                ListSecJoints.Add(val2)
            End If
            If booBasePlateJoint = False And booSamePropertyForPrimAndSec = False And booSpliceJoint = False Then
                If PropName = PrimProp Then
                    ListPrimMemb.Add(beamArray(r))
                    ret = objOpenSTAAD1.Geometry.GetMemberIncidence(beamArray(r), val1, val2)
                    ListPrimJoints.Add(val1)
                    ListPrimJoints.Add(val2)
                End If
            End If
        Next
        If booBasePlateJoint Then
            ret = objOpenSTAAD1.Support.getsupportnodes(supportArray)
            For r = 0 To dimsuppArray
                ListPrimJoints.Add(supportArray(r))
            Next
        End If
        Dim ListIntersection As New List(Of Integer)
        If (booSamePropertyForPrimAndSec Or booSpliceJoint) And ListSecMembTemp.Count > 0 Then
            Dim counter As Integer
            '  Dim EliminatedJoints As Integer = 0
            For a = 0 To ListSecJoints.Count - 1
                '     a = a - EliminatedJoints

                counter = 1
                For b = a + 1 To ListSecJoints.Count - 1
                    Try
                        If ListSecJoints.Item(a) = ListSecJoints.Item(b) Then
                            counter += 1
                            ListSecJoints.Remove(b)
                            '                EliminatedJoints += 1
                        End If
                    Catch ex As Exception
                    End Try
                Next
                If counter = 2 Then
                    If booSpliceJoint Then ListIntersection.Add(ListSecJoints.Item(a))
                ElseIf counter > 2 Then
                    If booSpliceJoint = False Then ListIntersection.Add(ListSecJoints.Item(a))
                End If
            Next
            For c = 0 To ListSecMembTemp.Count - 1
                ret = objOpenSTAAD1.Geometry.GetMemberIncidence(ListSecMembTemp.Item(c), val1, val2)
                For d = 0 To ListIntersection.Count - 1
                    If val1 = ListIntersection.Item(d) Or val2 = ListIntersection.Item(d) Then
                        ListSecMemb.Add(ListSecMembTemp.Item(c))
                        Exit For
                    End If
                Next
            Next
        Else
            ListIntersection = ListPrimJoints.Intersect(ListSecJoints).ToList
        End If
        If ListIntersection.Count > 0 Then
            If booSamePropertyForPrimAndSec And booSpliceJoint = False Then
                MsgBox("primary and secondary members have the same property " & PropName & _
                           " so the macro cannot understand which members are secondary and which primary." & _
                           " Right now all members have been selected therefore manually unselect primary members")
            End If
            ret = objOpenSTAAD1.Geometry.clearnodeselection
            ret = objOpenSTAAD1.Geometry.clearmemberselection
            For g = 0 To ListIntersection.Count - 1
                ret = objOpenSTAAD1.Geometry.SelectNode(ListIntersection.Item(g))
            Next
            For g = 0 To ListSecMemb.Count - 1
                ret = objOpenSTAAD1.Geometry.GetMemberIncidence(ListSecMemb.Item(g), val1, val2)
                For h = 0 To ListIntersection.Count - 1
                    If val1 = ListIntersection.Item(h) Or val2 = ListIntersection.Item(h) Then
                        ret = objOpenSTAAD1.Geometry.Selectbeam(ListSecMemb.Item(g))
                        Exit For
                    End If
                Next
            Next
        End If

        If booMsgReloadDataDisplayedAlready = False Then
            MsgBox(strReLoadData)
            booMsgReloadDataDisplayedAlready = True
        End If
    End Sub
    Private Sub btnPath_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnPath.Click
        OpenFileDialog1.Title = "choose SCS file to open"
        'OpenFileDialog1.Filter = strDocDialog
        If OpenFileDialog1.ShowDialog() = Windows.Forms.DialogResult.Cancel Then Exit Sub 'gaetano
        Dim sFilePathOpen As String
        sFilePathOpen = OpenFileDialog1.FileName
        If sFilePathOpen = Nothing Then Exit Sub
        If System.IO.File.Exists(sFilePathOpen) = False Then Exit Sub
        Dim exteN As String = sFilePathOpen.Substring(sFilePathOpen.Length - 3, 3)
        Select Case exteN
            Case Is = "fp1", "fp2", "me0", "cb8", "br9", "em3", "sp4", "ds1", "qs5", "qs6", "we1", "ap7", "xl1", "xl2"
                Dim pos As Integer = sFilePathOpen.LastIndexOf("\")
                txbSCSfileName.Text = sFilePathOpen.Substring(pos + 1, sFilePathOpen.Length - (pos + 1))
                WorkingPath = sFilePathOpen.Substring(0, pos + 1)
            Case Else
                MsgBox("this is not a valid SCS file")
        End Select
    End Sub
    Private Sub txbFilter_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txbFilter.TextChanged
        If txbFilter.Text = Nothing Then
            btnFilter.Enabled = False
        Else
            btnFilter.Enabled = True
        End If
    End Sub
    Private Sub txbSCSfileName_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txbSCSfileName.TextChanged
        If CheckIfSCSfileNameIsCompiled(False) Then
            btnSCSopenFile.Enabled = True
            btnDoStuff.Enabled = True
        End If
    End Sub
    Private Sub lbxSCS_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles lbxSCS.SelectedIndexChanged
        Dim value As Integer = lbxSCS.SelectedIndex
        Select Case value
            Case Is = 0
                txbSCSfileName.Text = ".fp1"
            Case Is = 1
                txbSCSfileName.Text = ".fp2"
            Case Is = 2
                txbSCSfileName.Text = ".xl1"
            Case Is = 3
                txbSCSfileName.Text = ".xl2"
            Case Is = 4
                txbSCSfileName.Text = ".qs5"
            Case Is = 5
                txbSCSfileName.Text = ".qs6"
            Case Is = 6
                txbSCSfileName.Text = ".em3"
            Case Is = 7
                txbSCSfileName.Text = ".ap7"
            Case Is = 8
                txbSCSfileName.Text = ".we0"
            Case Is = 9
                txbSCSfileName.Text = ".cb8"
            Case Is = 10
                txbSCSfileName.Text = ".ds1"
            Case Is = 11
                txbSCSfileName.Text = ".sp4"
            Case Is = 12
                txbSCSfileName.Text = ".br9"
        End Select
        lbxSCS.Visible = False
    End Sub
    Private Sub btnNewSCS_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnNewSCS.Click
        lbxSCS.Visible = True
    End Sub
End Class
Public Class FrameElement
    Private m_label As String
    Public Property Label() As String
        Get
            Return m_label
        End Get
        Set(ByVal value As String)
            m_label = value
        End Set
    End Property
    Public Sub New()
    End Sub
    Private m_coordpoint1(2) As Double
    Private m_coordpoint2(2) As Double
    Public Property CoordPoint1() As Double()
        Get
            Return m_coordpoint1
        End Get
        Set(ByVal value As Double())
            m_coordpoint1 = value
        End Set
    End Property
    Public Property CoordPoint2() As Double()
        Get
            Return m_coordpoint2
        End Get
        Set(ByVal value As Double())
            m_coordpoint2 = value
        End Set
    End Property
    Public Sub New(ByVal label As String, ByVal coord1() As Double, ByVal coord2() As Double)
        m_label = label
        If coord1.Count = 3 Then m_coordpoint1 = coord1
        If coord2.Count = 3 Then m_coordpoint2 = coord2
    End Sub
    Private m_vector(2) As Double
    Private m_vectornormalized(2) As Double
    Private m_length As Double
    Public ReadOnly Property VectorNormalized() As Double()
        Get
            For k = 0 To 2
                m_vector(k) = m_coordpoint2(k) - m_coordpoint1(k)
            Next
            m_length = Sqrt(m_vector(0) ^ 2 + m_vector(1) ^ 2 + m_vector(2) ^ 2)
            For k = 0 To 2
                m_vectornormalized(k) = m_vector(k) / m_length
            Next
            Return m_vectornormalized
        End Get
    End Property
    Public ReadOnly Property MainDirectionZvertical_0x_1y_2z_3xyPlane_4xzplane_5yzplane_6xyz() As Integer
        Get
            Dim refVal As Double = 0.95 'this means an angle approx between 72° and 90°
            Dim refVal2 As Double = 0.05
            If Abs(VectorNormalized(0)) >= refVal Then
                Return 0
            ElseIf Abs(m_vectornormalized(1)) >= refVal Then
                Return 1
            ElseIf Abs(m_vectornormalized(2)) >= refVal Then
                Return 2
            ElseIf Abs(m_vectornormalized(2)) <= refVal2 Then
                Return 3
            ElseIf Abs(m_vectornormalized(1)) <= refVal2 Then
                Return 4
            ElseIf Abs(m_vectornormalized(0)) <= refVal2 Then
                Return 5
            Else
                Return 6
            End If
        End Get
    End Property
End Class

Module CommonMethods
    Public Function AngleBetweenFrameElements(ByVal Frame1 As FrameElement, ByVal Frame2 As FrameElement) As Double 'angle in radians between frame elements
        Dim angleinRadians As Double = Acos(Frame1.VectorNormalized(0) * Frame2.VectorNormalized(0) + Frame1.VectorNormalized(1) * Frame2.VectorNormalized(1) + Frame1.VectorNormalized(2) * Frame2.VectorNormalized(2))
        If angleinRadians >= PI Then angleinRadians += -PI
        Return angleinRadians
    End Function
End Module

Public Class JointDataClass
    Private m_primarymemberisacolumn As Boolean = False
    Private m_frameelements() As FrameElement
    Private m_objname() As String
    Private m_pointnumber() As Integer
    Private m_propertyname() As String
    Private m_propertyrefvalue() As Double
    Private m_propertyrefvaluesorted() As Double
    Private m_objectcount As Integer
    Private m_objnameroot() As String
    Private m_objnode() As Integer '0 first joint, 1 second joint
    Private m_objnamesecondpart() As String
    Private m_baseplatejoint As Boolean = False
    Private m_bracejoint As Boolean = False
    Private m_splicejoint As Boolean = False
    Public Property SpliceJoint() As Boolean
        Get
            Return m_splicejoint
        End Get
        Set(ByVal value As Boolean)
            m_splicejoint = value
        End Set
    End Property
    Public Property BraceJoint() As Boolean
        Get
            Return m_bracejoint
        End Get
        Set(ByVal value As Boolean)
            m_bracejoint = value
        End Set
    End Property
    Public Property BasePlateJoint() As Boolean
        Get
            Return m_baseplatejoint
        End Get
        Set(ByVal value As Boolean)
            m_baseplatejoint = value
        End Set
    End Property
    Public Property ObjNode() As Integer()
        Get
            Return m_objnode
        End Get
        Set(ByVal value() As Integer)
            m_objnode = value
        End Set
    End Property
    Public Property PrimaryMemberIsaColumn() As Boolean
        Get
            Return m_primarymemberisacolumn
        End Get
        Set(ByVal value As Boolean)
            m_primarymemberisacolumn = value
        End Set
    End Property
    Public Property FrameElements() As FrameElement()
        Get
            Return m_frameelements
        End Get
        Set(ByVal value() As FrameElement)
            m_frameelements = value
        End Set
    End Property
    Public ReadOnly Property ObjectCount() As Integer
        Get
            Return m_objectcount
        End Get
    End Property
    Public Property ObjName() As String()
        Get
            Return m_objname
        End Get
        Set(ByVal value As String())
            m_objname = value
        End Set
    End Property
    Public Property PointNumber() As Integer()
        Get
            Return m_pointnumber
        End Get
        Set(ByVal value As Integer())
            m_pointnumber = value
        End Set
    End Property
    Public Property PropertyRefValue() As Double()
        Get
            Return m_propertyrefvalue
        End Get
        Set(ByVal value As Double())
            m_propertyrefvalue = value
        End Set
    End Property
    Public Property PropertyName() As String()
        Get
            Return m_propertyname
        End Get
        Set(ByVal value As String())
            m_propertyname = value
        End Set
    End Property
    Public Sub New(ByVal objcount As Integer)
        m_objectcount = objcount
        If m_objectcount = 0 Then
            MsgBox("problem")
        End If
        ReDim m_pointnumber(m_objectcount - 1)
        ReDim m_objname(m_objectcount - 1)
        ReDim m_propertyname(m_objectcount - 1)
        ReDim m_objnameroot(m_objectcount - 1)
        ReDim m_objnode(m_objectcount - 1)
        ReDim m_objnamesecondpart(m_objectcount - 1)
        ReDim m_propertyrefvalue(m_objectcount - 1)
        ReDim m_propertyrefvaluesorted(m_objectcount - 1)
    End Sub
    Private m_guessedprimarymember_name As String
    Private m_guessedsecondarymember_name() As String
    Public Property GuessedPrimaryMember_Name() As String
        Get
            Return m_guessedprimarymember_name
        End Get
        Set(ByVal value As String)
            m_guessedprimarymember_name = value
        End Set
    End Property
    Public Property GuessedSecondaryMember_Name() As String()
        Get
            Return m_guessedsecondarymember_name
        End Get
        Set(ByVal value() As String)
            m_guessedsecondarymember_name = value
        End Set
    End Property
    Private m_guessedprimarymember_property_OverWrite As Boolean = False
    Public Property GuessedPrimaryMember_property_OverWrite() As Boolean
        Get
            Return m_guessedprimarymember_property_OverWrite
        End Get
        Set(ByVal value As Boolean)
            m_guessedprimarymember_property_OverWrite = value
            CheckIfCustomAssignedPrimaryMemberPropertyIsOkInThisJoint()
        End Set
    End Property
    Private Sub CheckIfCustomAssignedPrimaryMemberPropertyIsOkInThisJoint()
        If m_baseplatejoint = False Then
            If m_guessedprimarymember_property_OverWrite Then
                Dim booCheckIsOk = False
                For j = 0 To m_objectcount - 1
                    If m_guessedprimarymember_property = m_propertyname(j) Then
                        m_guessedprimarymember_name = m_objname(j)
                        m_guessedprimarymember_index = j
                        booCheckIsOk = True
                        Exit For
                    End If
                Next
                If booCheckIsOk Then
                    m_jointisverifiedtogiveloads = True
                Else
                    m_jointisverifiedtogiveloads = False
                    MsgBox("Joint " & m_label & " doesn't have any member connected with the primary member property " & m_guessedprimarymember_property & _
                            "therefore its load data will not be included in the export")
                End If
            End If
        End If
    End Sub
    Private m_jointisverifiedtogiveloads As Boolean = False
    Public ReadOnly Property JointIsVerifiedToGiveLoads() As Boolean 'this is false when the primary member property assigned can't be found in the joint
        Get
            Return m_jointisverifiedtogiveloads
        End Get
    End Property
    Private m_guessedprimarymember_property As String
    Private m_guessedsecondarymember_property As String
    Public Property GuessedPrimaryMember_property() As String
        Get
            If m_guessedprimarymember_property_OverWrite = False Then m_guessedprimarymember_property = m_propertyname(GuessedPrimaryMember_index)
            Return m_guessedprimarymember_property
        End Get
        Set(ByVal value As String)
            m_guessedprimarymember_property = value
            CheckIfCustomAssignedPrimaryMemberPropertyIsOkInThisJoint()
        End Set
    End Property
    Public Property GuessedSecondaryMember_property() As String
        Get
            Return m_guessedsecondarymember_property
        End Get
        Set(ByVal value As String)
            m_guessedsecondarymember_property = value
        End Set
    End Property
    Private m_guessedprimarymember_index As String
    Private m_guessedsecondarymember_index() As String
    Public ReadOnly Property GuessedPrimaryMember_index() As String
        Get
            ' m_guessedprimarymember_index = GetIndexByObjName(m_guessedprimarymember_name)
            Return m_guessedprimarymember_index
        End Get
        'Set(ByVal value As String)
        '    m_guessedprimarymember_index = value
        'End Set
    End Property
    Public ReadOnly Property GuessedSecondaryMember_index() As String()
        Get
            'For i = 0 To m_guessedsecondarymember_name.Count - 1
            '    m_guessedsecondarymember_index(i) = GetIndexByObjName(m_guessedsecondarymember_name(i))
            'Next
            Return m_guessedsecondarymember_index
        End Get
        'Set(ByVal value As String)
        '    m_guessedsecondarymember_index = value
        'End Set
    End Property
    Private Function GetIndexByObjName(ByVal name As String) As Integer
        For k = 0 To m_objectcount - 1
            If m_objname(k) = name Then
                Return k
            End If
        Next
        Return Nothing
    End Function
    Public ReadOnly Property ObjectNameRoot() As String()
        Get
            Return m_objnameroot
        End Get
    End Property
    Private m_label As String
    Public Property Label() As String
        Get
            Return m_label
        End Get
        Set(ByVal value As String)
            m_label = value
        End Set
    End Property
    Private m_listofsecondarymember
    Public Sub GetObjNameRoot(ByVal j As Integer)
        m_objnameroot(j) = m_objname(j)
    End Sub
    Private m_SecMembersInThisJointCount As Integer = 0
    Private m_PrimMembersInThisJointCount As Integer = 0
    Public Sub GuessPrimaryMembersAndAssignSecMembers(ByVal SecMembers As String())
        m_SecMembersInThisJointCount = 0
        For j = 0 To m_objectcount - 1
            'GetObjNameRoot(j) not needed since it has been called to assign values to FrameElements
            For i = 0 To SecMembers.Count - 1
                If m_objnameroot(j) = SecMembers(i) Then
                    ReDim Preserve m_guessedsecondarymember_name(m_SecMembersInThisJointCount)
                    ReDim Preserve m_guessedsecondarymember_index(m_SecMembersInThisJointCount)
                    m_guessedsecondarymember_name(m_SecMembersInThisJointCount) = m_objname(j)
                    m_guessedsecondarymember_index(m_SecMembersInThisJointCount) = j
                    m_guessedsecondarymember_property = m_propertyname(j)  'revision on 20141127
                    m_SecMembersInThisJointCount += 1
                End If
            Next
        Next
        If m_SecMembersInThisJointCount = 0 Then
            MsgBox("no secondary member selected for joint " & m_label)
            m_jointisverifiedtogiveloads = False
        Else
            m_PrimMembersInThisJointCount = 0
            For j = 1 To m_objectcount - 1
                For k = 0 To m_SecMembersInThisJointCount - 1
                    If j <> m_guessedsecondarymember_index(k) Then
                        If m_splicejoint = True Then
                            If m_propertyname(j) = m_propertyname(m_guessedsecondarymember_index(k)) Then
                                m_guessedprimarymember_name = m_objname(j)
                                m_guessedprimarymember_index = j
                                m_jointisverifiedtogiveloads = True
                            End If
                        Else
                            Dim anG As Double = AngleBetweenFrameElements(m_frameelements(m_guessedsecondarymember_index(k)), m_frameelements(j))
                            Dim angDegrees As Double = anG / PI * 180
                            If Abs(90 - angDegrees) <= acceptedangleDeltafrom90() Then
                                m_guessedprimarymember_name = m_objname(j)
                                m_guessedprimarymember_index = j
                                m_jointisverifiedtogiveloads = True
                            End If
                        End If
                    End If
                Next
            Next
        End If

    End Sub
    Private Function acceptedangleDeltafrom90() As Double
        If m_bracejoint Then
            Return 75
        Else
            Return 15
        End If
    End Function

End Class