Read Nodes from CDB - database with python

So after running the ‘read_nodes.py’ code Sofistik has as an example, i tried replacing the database they gave as an example with my own. Unfortunately, now the while loop exists after 1 pass.
CDB Status: 1 (instead of 3)
and ie.value will be 3 after the first pass through the while loop.
Below you will find a picture of the database and the code. I also tried other databases but that didnt work either.
I am using the 2024 version, have an educational license and use python3.11 if that is important.
If any of you have an idea what the problem/my mistake could be, any help would be greatly appreciated

# +============================================================================+
# | Company:   SOFiSTiK AG                                                     |
# | Version:   SOFiSTIK 2023                                                   |
# +============================================================================+

# import all types from sofistik_daten.py, original file can be found by following
# --> examples/python/sofistik_daten.py
from sofistik_daten import *
import os                     # for the environment variable necessary
import platform               # checks the python platform
from ctypes import *          # read the functions from the cdb

## This example has been tested with Python ...?
print ("The path variable=", os.environ["Path"])

# Check the python platform (32bit or 64bit)
print ("Python architecture=", platform.architecture())
sofPlatform = str(platform.architecture())

# Get the DLLs (32bit or 64bit DLL)
if sofPlatform.find("32Bit") < 0:
    # Set environment variable for the dll files
    print ("Hint: 64bit DLLs are used")

    # Set DLL dir path - new in PY 3.8 for ctypes
    # See: https://docs.python.org/3/whatsnew/3.8.html#ctypes
    os.add_dll_directory(r"C:\Program Files\SOFiSTiK\2024\SOFiSTiK 2024\interfaces\64bit")
    os.add_dll_directory(r"C:\Program Files\SOFiSTiK\2024\SOFiSTiK 2024")

    # Get the DLL functions
    myDLL = cdll.LoadLibrary("sof_cdb_w-2024.dll")
    py_sof_cdb_get = cdll.LoadLibrary("sof_cdb_w-2024.dll").sof_cdb_get
    py_sof_cdb_get.restype = c_int

    py_sof_cdb_kenq = cdll.LoadLibrary("sof_cdb_w-2024.dll").sof_cdb_kenq_ex
else:
    # Set environment variable for the DLL files
    print ("Hint: 32bit DLLs are used")

    # Set DLL dir path - new in PY 3.8 for ctypes
    # See: https://docs.python.org/3/whatsnew/3.8.html#ctypes

    os.add_dll_directory(r"C:\\Program Files\\SOFiSTiK\\2024\\SOFiSTiK 2024\\interfaces\32bit")
    os.add_dll_directory(r"C:\\Program Files\\SOFiSTiK\\2024\\SOFiSTiK 2024")

    # Get the DLL functions
    myDLL = cdll.LoadLibrary("cdb_w31.dll")
    py_sof_cdb_get = cdll.LoadLibrary("cdb_w31.dll").sof_cdb_get
    py_sof_cdb_get.restype = c_int

    py_sof_cdb_kenq = cdll.LoadLibrary("cdb_w31.dll").sof_cdb_kenq_ex

# Connect to CDB
Index = c_int()
cdbIndex = 99

# input the cdb path here

fileName = r"...\read_nodes.cdb"


# important: Unicode call!
Index.value = myDLL.sof_cdb_init(fileName.encode('utf8'), cdbIndex)
# get the CDB status
cdbStat = c_int()
cdbStat.value = myDLL.sof_cdb_status(Index.value)
# Print the Status of the CDB
print ("CDB Status:", cdbStat.value)

pos = c_int(0)
datalen = c_int(0)
a = c_int()
ie = c_int(0)
datalen.value = sizeof(CNODE)
RecLen = c_int(sizeof(cnode))

"""
do while ie == 0, see cdbase.chm, Returnvalue.
    = 0 -> No error
    = 1 -> Item is longer than Data
    = 2 -> End of file reached
    = 3 -> Key does not exist
"""

while ie.value < 2:
    ie.value = py_sof_cdb_get(Index, 210, 0, byref(cnode), byref(RecLen), 1)
    ######print(ie.value) -> 3
    print("{:10d}{:10d}{:10d}{:10d}{:10.2f}{:10.2f}{:10.2f}".format(
        cnode.m_nr,      # node-number
        cnode.m_inr,     # internal node-number
        cnode.m_kfix,    # degree of freedoms
        cnode.m_ncod,    # additional bit code
        cnode.m_xyz[0],  # x coordinates
        cnode.m_xyz[1],  # y coordinates
        cnode.m_xyz[2])  # z coordinates
    )
    # Always read the length of record before sof_cdb_get is called
    RecLen = c_int(sizeof(cnode))

# Close the CDB, 0 - will close all the files
myDLL.sof_cdb_close(0)

# Print again the status of the CDB, if status = 0 -> CDB Closed successfully
cdbStat.value = myDLL.sof_cdb_status(Index.value)
if cdbStat.value == 0:
    print ("CDB closed successfully, status = 0")

You are checking record 210 instead of 20

As you working with the educational version, you also need to work with the educational DLL functions, so place ‘edu’ in between your dll functions as below.

 # Get the DLL functions
    myDLL = cdll.LoadLibrary("sof_cdb_w_edu-2024.dll")
    py_sof_cdb_get = cdll.LoadLibrary("sof_cdb_w_edu-2024.dll").sof_cdb_get
    py_sof_cdb_get.restype = c_int

    py_sof_cdb_kenq = cdll.LoadLibrary("sof_cdb_w_edu-2024.dll").sof_cdb_kenq_ex
1 Like

Yes this was the issue, thank you!