AutoCAD

AutoCAD Map 3D .NET API

 
AutoCAD
 
 
 

AutoCAD Map 3D relies on AutoCAD for much of its functionality. It is important to understand some basic AutoCAD concepts before writing AutoCAD Map 3D applications. For complete details, refer to the AutoCAD developer documentation.

In particular, managing objects in the AutoCAD database is important.

Transactions

The AutoCAD database uses a transaction model for access to all objects.

To use any object in the database, start a transaction and use the transaction to open the database object in either read-only or read-write mode. Transaction.Open() returns a generic reference. Cast that to the type of object being returned. For example, given a database object id for a MapBook object, the following will return a reference to the object:

Dim bookObj As MapBook.Book
bookObj = CType(trans.GetObject(mapBookId, OpenMode.ForWrite),
   MapBook.Book)

Short examples in this guide may not include all the transaction processing, so they can highlight the concepts being discussed. In all cases, though, if any changes are being made to the drawing, it should be assumed that the following general structure is in place:

Dim trans As Transaction = Nothing
Dim docs As DocumentCollection = Application.DocumentManager
Dim activeDoc As Document = docs.MdiActiveDocument
Try
   trans = activeDoc.TransactionManager.StartTransaction()
   ' 
   ' Open object(s)
   ' 
   Dim bookObj As MapBook.Book
   bookObj = CType(trans.GetObject(mapBookId, OpenMode.ForWrite),
      MapBook.Book)
   '
   ' Insert code to process transaction
   '
   ' Commit transaction
   '
   trans.Commit()
Catch
   '
   ' Handle exception, and cancel transaction
   '
Finally
   trans.Dispose()
End Try

Although transactions can be nested, this is not recommended. One complication is that adding an entity takes place immediately, but removing an entity does not take effect until the transaction has been committed.

NoteMany examples in this guide assume that activeDoc refers to the active document.