Close

Relief for ODA Team in Ukraine

Learn more
ODA Drawings SDK
Creating and Reading a Database

Drawings SDK allows a host application to provide an implementation for certain services, including status notification (for file loading, saving, etc.), font file locating, etc. These services are defined by the OdDbHostAppServices class, and a default implementation of OdDbHostAppServices is provided in the ExHostAppServices class.

A Database object is represented by the OdDbDatabase class and can be created by an OdDbHostAppServices object which provides two options to create a Database instance:

  • Create a database by the OdDbHostAppServices::createDatabase() method. If the createDefault has the true value, the database will be created and populated with the default set of nine symbol tables:
    • OdDbBlockTable
    • OdDbLayerTable
    • OdDbViewTable
    • OdDbLinetypeTable
    • OdDbViewportTable
    • OdDbTextStyleTable
    • OdDbDimStyleTable
    • OdDbRegAppTable
    • OdDbUCSTable

    Some of the symbol tables of the initial database already contain one or more records. The layer table contains one record, layer 0. The block table initially contains three records: *MODEL_SPACE, *PAPER_SPACE, and *PAPER_SPACE0. The linetype table always has CONTINUOUS, BY_LAYER, and BY_BLOCK linetype table records. If the false value is passed, an empty database will be created, and it can be populated by the OdDbDatabase::readFile() method:

    
    void OdDbDatabase::readFile(OdStreamBuf* pStreamBuf, bool partialLoad = false, OdDbAuditInfo *pAuditInfo = 0, const OdPassword& password = OdPassword(), bool allowCPConversion = false); 
    void OdDbDatabase::readFile(const OdString& filename, bool partialLoad = false, Oda::FileShareMode shareMode = Oda::kShareDenyWrite, const OdPassword& password = OdPassword(), bool allowCPConversion = false);
    
  • Create an empty database which can be populated by reading a .dwg file using the OdDbHostAppServices::readFile() method. Use the appropriate signature for reading from a file or from a stream buffer.

For example, to create a default database (where svsc is an instance of OdDbHostAppServices):


OdDbDatabasePtr pDb = svcs.createDatabase(true);

To create an empty database and then populate it by reading an input file:


OdDbDatabasePtr pDb = svcs.createDatabase(false);
pDb->readFile("drawing1.dwg");

To create a database by reading an input file:


OdDbDatabasePtr pDb = svcs.readFile("drawing1.dwg");

For more details, see Creating Host Applications.

Copyright © 2002 – 2022. Open Design Alliance. All rights reserved.