Reading data from CDB

I’ve followed the basic tutorials on how to read from a CDB file, and so far everything works.
I understand how to read some elements from the CDB using the sample code.

If I understand correctly, it’s just a matter of providing the correct keys. (kwh & kwl) and iterating over the DB until you’re reached the record you need.

But the documentation is really confusing me.
For the life of me I don’t understand the difference between the following statements

@Rec: 03/ID:0 AXIS | Geometric Axis
@Rec: 03/ID:- AXIS_REF | Reference to another Geometry
@Rec: 03/ID:?? AXIS_GEO |Geometric properties

They ALL have KWH:3 , but I don’t understand the KWL part.
What is the difference between:
/ID 0
/ID ?
/ID +
/ID -
/NR 0
/NR0:0
/NR0:+
/NR0:-
/NR0:??

just check cdbase.chm → SOFiSTiK Definitions → chapter 1.
best regards, sb

Thanks for your reply, however even after reading it’s not entirely clear to me.
I did some looking into the database info:
image

I wanted to check if I could read materials from a CDB file. Just to check if I understood the CDB structure, and the DLL’s interaction with it.

Using the Database info I could determine that I would find 2 materials. 1 concrete; 2 steel inside the 1/1 & 1/2 respectively.

When I go to look using code. It suddenly fails.
Here’s what I do. Can you perhaps find a flaw in my logic?

def get_db_entries(idx:int, kwh:int, kwl:int, data_type:type):
        """Get DB entries of provided kwh, kwl and datatype"""
        import copy        
        logger.info(f"Looking in {kwh}/{kwl} for type:{data_type} in db: %s" % self.db_id)
        db_id = idx
        
        data_target = data_type() # create instande of datatype
        data_len = c_int(sizeof(data_type)) # this also matches sizeof(data_target)
        data_set = []
        ie = c_int(0)
        
        while ie.value < 2:
            # INTERACTIONS is a global object that houses my loaded DLL and provides acces to my dll
            ie.value = INTERACTIONS.cdb_get(db_id, kwh, kwl, byref(data_target), byref(data_len), 1)
            data_len.value = sizeof(data_target) # new reclen

            # copies the info at returned pointer into an object so that I can retain the information in a simple python list
            data_copy = copy.copy(data_target)
            data_set.append(data_copy)
            if ie.value == 3:
                return
            logger.info("Get DB returned  with ie: %s" %ie.value )    
            yield data_copy
            
        logger.info("Get DB Entries exited with ie: %s" %ie.value )

I have a testfunction to verify my findings

def test_db_entries(db_id):
    if does_key_exist(1, 1):
        logger.info("Key exists")
        # CMAT is an import from the sofistik_datan.py file
        for entry in db.get_db_entries(db_id, 1, 1, CMAT):
            logger.info("Found record %s" % entry)

What I do not understand is that my output looks somewhat like the following:

key exists
Looking for 1/1 for type CMAKE in db: 1
Get DB returned with ie: 3

Any ideas what I’m doing wrong? The keys SHOULD exist, since I can read them using the DB information.

Check out this example in your installation folder:
C:\Program Files\SOFiSTiK\2022\SOFiSTiK 2022\interfaces\examples\python\python_3.x\single_span_girder\single_span_girder.py

Possible error from what I can see in your code:

  • data_len.value = sizeof(data_target) # new reclen should be
    data_len.value = c_int(sizeof(data_target))
  • Maybe cmat_conc instead of cmat?

But to be honest it is impossible to error check your code (unless something obvious pops up) since your bundling dll:s etc in an object.

Try to access the cdb without the extra bells and whistles (INTERACTION object, functions, etc). Once you get that to work, add the extras step-by-step.

@gertjanvdbvk Did you ever find a solution to this?