Read the node properties#
Problem Description#
In this example we will read the nodes data from the database.
Following values are extracted:
NR
(node number)INR
(internal node number)KFIX
(degree of freedoms, bitwise encoded)NCOD
(additional bit code)X
(global X coordinate)Y
(global Y coordinate)Z
(global Z coordinate)
The nodes description can be found in CDBASE.CHM as shown in figure below:
The [INT]
means that the data-type is integer. The data-type can easily be checked in the
data-type list given in the example.
Problem Solution#
The example can be found by following:
C:\<sofistik_installation>\2024\SOFiSTiK 2024\interfaces\examples\vb.net\read_nodes
Here is a code example how to read the nodes from the CDB:
Imports System.Runtime.InteropServices
Module main
'In this example, 64bit DLLs are used
Public Declare Function sof_cdb_init Lib "sof_cdb_w-2024.dll" Alias "VB_sof_cdb_init" (
ByVal name_ As String,
ByVal InitType_ As Integer
) As Integer
Public Declare Function sof_cdb_status Lib "sof_cdb_w-2024.dll" Alias "VB_sof_cdb_status" (
ByVal Index_ As Integer
) As Integer
Public Declare Function sof_cdb_close Lib "sof_cdb_w-2024.dll" Alias "VB_sof_cdb_close" (
ByVal Index_ As Integer
) As Integer
Public Declare Function sof_cdb_get Lib "sof_cdb_w-2024.dll" Alias "VB_sof_cdb_get" (
ByVal Index_ As Integer,
ByVal kwh_ As Integer,
ByVal kwl_ As Integer,
ByRef data As CNODE,
ByRef datalen_ As Integer,
ByVal pos_ As Integer
) As Integer
Sub Main()
Dim Filename As String
Dim Index As Integer
Dim Path As String
Dim analysisPath As String
Dim datalen As Integer
Dim data As New CNODE
Dim analysisPath2 As String
'Path of the SOFiSTIK Directory
analysisPath = "C:\sofistik_installation\trunk\SOFiSTiK trunk\interfaces\64bit"
analysisPath2 = "C:\sofistik_installation\trunk\SOFiSTiK trunk"
'Set the environment variable
Path = Environment.GetEnvironmentVariable("path")
Path = analysisPath2 + ";" + analysisPath + ";" + Path
Environment.SetEnvironmentVariable("path", Path)
'Filename = full path with name of the cdb
Filename = "S:\test\simple_span_girder.cdb"
' To connect to the CDB
Index = sof_cdb_init(Filename, 99)
If Index < 0 Then
Console.WriteLine("ERROR: Index= " & Index & " < 0 - see clib1.h for meaning of error codes")
Console.ReadKey()
Exit Sub
ElseIf Index = 0 Then
Console.WriteLine("ERROR: Index= " & Index & " - The File is not a database")
Console.ReadKey()
Exit Sub
End If
' Redim the m_XYZ array
' This step is necessary because in VB.NET fixed array in structures are not supported
ReDim data.m_XYZ(2)
' Get the data-length
datalen = Marshal.SizeOf(data)
' Print the values
Console.WriteLine(
"{0,-15} {1,-15} {2,-15} {3,-15} {4,-15} {5,-15} {6,-15}",
"m_NR", "m_INR", "m_KFIX", "m_NCOD", "m_X", "m_Y", "m_Z")
Do While sof_cdb_get(Index, 20, 0, data, datalen, 1) < 2
Console.WriteLine(
"{0,-15} {1,-15} {2,-15} {3,-15} {4,-15} {5,-15} {6,-15}",
data.m_NR,
data.m_INR,
data.m_KFIX,
data.m_NCOD,
data.m_XYZ(0),
data.m_XYZ(1),
data.m_XYZ(2))
datalen = Marshal.SizeOf(data)
Loop
'This outputs the status of the CDB, please refer to cdbase.chm for more details
Console.WriteLine("Index: " & Index)
Console.WriteLine("CDB Status: " & sof_cdb_status(Index))
'Close the CDB
Call sof_cdb_close(0)
'Check the CDB Status
If sof_cdb_status(Index) = 0 Then
Console.WriteLine("CDB closed succesfully, status = 0")
End If
Console.Write("Press any <key> to close the program")
Console.ReadKey()
End Sub
End Module