In general, the procedure for creating database resident objects consists of the following steps:
Open the parent object for writing (the parent is the object that will own the newly created object within the database hierarchy).
Create a new object.
Set the minimal number of properties required to add the object to the database:
Table entries — Must have a name before they can be added to a database.
Entities — Normally can be added to a database without setting any properties.
Objects — Normally can be added to a database without setting any properties.
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.
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.
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:
Open the table to which the new object will be added, in OdDb::kForWrite mode.
Create the new table entry.
Set the name of the entry, and any other desired properties.
Add the new entry to the open table object.
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: