DBDictionary

Hello
I have a software that currently works with Autocad that writes and reads data structures within the dwg using the DBDictionary class.
Bringing the software to BricsCad I have a problem. With random frequency it cannot access the data without giving an error, only in debug I see that an exception is thrown that I cannot read.
What do you know do I have to manage access to the DWG database differently or is there something else?

Comments

  • No two APIs are identical. There are many minor differences in the API that can cause old code to fail. You need to debug your code step by step. For example, BricsCAD may issue different exception codes and this is enough for old code to interpret them incorrectly.

  • The problem is that I can't see exceptions.
    This is my code to open the database.

    public DBDictionary OpenDatabase(string database, OpenMode mode) {
    DBDictionary fcCollection;

    DocumentLock loc = doc.LockDocument();
    using (loc) {


    using (Transaction trans = db.TransactionManager.StartTransaction()) {

    NOD = (DBDictionary)trans.GetObject(db.NamedObjectsDictionaryId, mode, false);
    // se esiste apro e ritorno
    try {
    fcCollection =
    (DBDictionary)trans.GetObject(NOD.GetAt(database), mode, false);
    db_nome = database;
    }
    // altrimenti se aperto in scrittura lo creo e lo aggiungo
    catch {
    if (mode != OpenMode.ForWrite) {
    fcCollection = null;
    } else {
    fcCollection = new DBDictionary();
    NOD.SetAt(database, fcCollection);
    trans.AddNewlyCreatedDBObject(fcCollection, true);
    fcCollection =
    (DBDictionary)trans.GetObject(NOD.GetAt(database), mode, false);
    db_nome = database;

    }
    }
    trans.Commit();
    }
    }
    return fcCollection;
    }

    The method that doesn't work is the GetObject but I can't see why.

    To open the dtaabse of the dwg do you use a method like mine or do you do it differently? ...

  • Its_Alive
    edited December 2024

    return fcCollection; is bad code

    fcCollection is a transaction resident object, it’s shut down at trans.Commit(); Also NOD.GetAt should be preceded by a NOD.Has check. where does 'db' come from?

    why is the function named OpenDatabase when it does not open a database, but a NOD entry?

  • The code with objectArx works. The names can be misleading, yes, but it works.
    With BricsCad it doesn't work.

    Any idea why or do you have a code example that works?

  • Its_Alive
    edited December 2024

    “Any idea why”

    The transaction is designed to open, then close objects and commit changes. You are returning an object that you asked the transaction to close.

    Imagine, File Open -> File Close -> File Read… poof crash