Drawings SDK Developer Guide > Working with .dwg Files > Introduction > Basics of Database Operations and Database Objects > Working with Database Objects > Creating Objects
Creating Objects

In general, the procedure for creating database resident objects consists of the following steps:

  1. Open the parent object for writing (the parent is the object that will own the newly created object within the database hierarchy).
  2. Create a new object.
  3. Set the minimal number of properties required to add the object to the database:
    1. Table entries — Must have a name before they can be added to a database.
    2. Entities — Normally can be added to a database without setting any properties.
    3. Objects — Normally can be added to a database without setting any properties.
  4. Add the new object to its parent, getting back the new Object ID for this object. Adding the object to a database does not change its open status—it will remain in the same state (open for write) after it has been added to a database.
  5. Set the remaining properties for the new object. Note that some properties can only be set on a database resident object, so as a general rule it is simpler to set all remaining properties (other than those specified in point 3 above) after the object has been added to the database.
  6. Close the object and its parent. This happens implicitly when the smart pointers used to open and create the objects are destroyed, or it can be done explicitly by calling the OdSmartPtr::release() method on the appropriate smart pointer objects.

In the case of creating new table objects:

  1. Open the table to which the new object will be added, in OdDb::kForWrite mode.
  2. Create the new table entry.
  3. Set the name of the entry, and any other desired properties.
  4. Add the new entry to the open table object.
  5. Close the table entry and table objects (this is done automatically when the smart pointers holding references to these objects go out of scope).

The following examples illustrate the procedures for creating entities and layers:

Creating Entities

Creating Layers

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