# +============================================================================+ # | Company: SOFiSTiK AG | # | Version: SOFiSTIK 2020 | # +============================================================================+ ################################################################################ # ABOUT: # In this example we will show how to use the sof_lib_ps2cs() function # sof_lib_ps2cs() converts integer values to string # 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 3.7 (64-bit) print("The path variable=", os.environ["Path"]) # Check the python platform (32bit or 64bit) print("Python architecture=", platform.architecture()) sofPlatform = str(platform.architecture()) def lng2txt(curLong, nrChar): decode = "" if nrChar == 4: part1_4char = (curLong & 0xFF000000) // 0x1000000 & 0xFF part2_4char = (curLong & 0xFF0000) // 0x10000 part3_4char = (curLong & 0xFF00) // 0x100 part4_4char = curLong & 0xFF if part4_4char != 0: decode = decode + chr(part4_4char) if part3_4char != 0: decode = decode + chr(part3_4char) if part2_4char != 0: decode = decode + chr(part2_4char) if part1_4char != 0: decode = decode + chr(part1_4char) if nrChar == 2: part1_2char = (curLong & 0xFFFF0000) // 0x10000 & 0xFFFF part2_2char = curLong & 0xFFFF if part2_2char != 0: decode = decode + chr(part2_2char) if part1_2char != 0: decode = decode + chr(part1_2char) return decode; # 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\2020\SOFiSTiK 2020\interfaces\64bit") os.add_dll_directory(r"C:\Program Files\SOFiSTiK\2020\SOFiSTiK 2020") # Get the DLL functions myDLL = cdll.LoadLibrary("sof_cdb_w-70.dll") py_sof_cdb_get = cdll.LoadLibrary("sof_cdb_w-70.dll").sof_cdb_get py_sof_cdb_get.restype = c_int py_sof_cdb_kenq = cdll.LoadLibrary("sof_cdb_w-70.dll").sof_cdb_kenq_ex py_sof_lib_ps2cs = cdll.LoadLibrary("sof_cdb_w-70.dll").sof_lib_ps2cs py_sof_lib_cs2ps = cdll.LoadLibrary("sof_cdb_w-70.dll").sof_lib_cs2ps 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:\sofistik_installation\2020\SOFiSTiK 2020\interfaces\32bit") os.add_dll_directory(r"C:\sofistik_installation\2020\SOFiSTiK 2020") # 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 py_sof_lib_ps2cs = cdll.LoadLibrary("cdb_w31.dll").sof_lib_ps2cs py_sof_lib_cs2ps = cdll.LoadLibrary("cdb_w31.dll").sof_lib_cs2ps # Connect to CDB Index = c_int() cdbIndex = 99 # Set the CDB Path # e.g. fileName = "S:\\test\\read_nodes.cdb" fileName = r"S:\test\brisi\t-beam_shear_web_flange.cdb" # important: Unicode call! Index.value = myDLL.sof_cdb_init(fileName.encode('utf8'), cdbIndex) cdbStat = c_int() # get the CDB status 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) ie = c_int(0) datalen.value = sizeof(CSECT_TXT) RecLen = c_int(sizeof(csect_txt)) """ 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 """ txt = "" while ie.value == 0: ie.value = py_sof_cdb_get(Index, 9, 1, byref(csect_txt), byref(RecLen), 1) if csect_txt.m_id == 19: for str_part in csect_txt.m_txt: if str_part == 0: break else: txt+="{0}".format(lng2txt(str_part, 2)) # Always read the length of record before sof_cdb_get is called RecLen = c_int(sizeof(csect_txt)) # Print the decoded TXT print(txt) # 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")