PPT_LOGO_4b
‹#›
© 2009 Autodesk
Autodesk Developer Network
§Similar to AutoCAD entities – TestWallAdd command
§
§
§
§
§
§
§
§
§
§
§
§
§
§
§
§2a - Aec Basics.vb > AcaNetWallAdd command
' Always call two SetXXX methods after NEW
Dim w As New Wall()
w.SetDatabaseDefaults(db) ' this also calls any subSetDatabaseDefaults
w.SetToStandard(db)
w.SetDefaultLayer() ' set the layer according to the layer key
' Set any specific properties, e.g.:
w.Set(pStart, pEnd, Vector3d.ZAxis)
' Add to ModelSpace
Dim bt As BlockTable = _
    CType(tr.GetObject(db.BlockTableId, OpenMode.ForRead), BlockTable)
Dim btr As BlockTableRecord = _
    CType(tr.GetObject(bt(BlockTableRecord.ModelSpace),
    OpenMode.ForWrite), BlockTableRecord)
btr.AppendEntity(w)
' When an object is added to db, we must also let the transaction know:
tr.AddNewlyCreatedDBObject(w, True)
Object Creation
Aec Entities
Object creation in ACA is similar to AutoCAD entity creation. The basic steps are:
1. Allocate a new object of the type you want
2. Initialize the object
3. Set additional values (in some cases this is also required AFTER the object has be
added to the database)
4. Start a transaction (note this can be done anywhere, but must be done before attempting
the database changes)
5. Open the container where the object will reside (ie. Model Space)
6. Append the object to modelspace
7. Notify the transaction of the new object and commit when finished

When initializing an ACA entity (anything derived from Autodesk.Aec.DatabaseServices.Entity),
you will need to call the following two functions:
 SetDatabaseDefaults
 SetToStandard
The SetDatabaseDefaults function is an AutoCAD API which will establish basic entity level properties such as layer, linetype, and color. The SetToStandard function provides object initialization and some default values to make the object “valid” without further initialization. The concept is that by making this call, you are guaranteed that the object will have its data filled with valid values without any further initialization. For example, simply allocating a wall without any further initialization will provide settings for the base height, thickness, and cleanup radius.

When initializing an ACA Object (anything derived from Autodesk.Aec.DatabaseServices.DBObject, but is NOT an Entity), you need to call:
 SubSetDatabaseDefaults.
the reason for SubSetDatabaseDefaults is because of a minor AutoCAD limitation. On the ObjectARX side, there is a method implemented at the entity level called subSetDatabaseDefaults. The AutoCAD framework calls this method for any derived entity when the setDatabaseDefaults is called. This is why the AEC side does NOT require an explicit call to the subSetDatabaseDefaults for an entity. However, there is no automatic framework for the DB object level, so the SubSetDatabaseDefaults should be explicitly called in order for the object to be setup correctly (ie. db references to other objects are often initialized here).