David,
I had a look at one of the Methods from that book today.
It seemed a little verbose, so I had a look at an option in C# the way I thought I'd write it if I was trying to teach someone.
Here's the comparison.
The book VB code :
<CommandMethod("DrawALineA")> _
Sub DrawALineA()
Dim myTransMan As DatabaseServices.TransactionManager
Dim myTrans As DatabaseServices.Transaction
Dim myDWG As ApplicationServices.Document
Dim myBT As DatabaseServices.BlockTable
Dim myBTR As DatabaseServices.BlockTableRecord
'Get the active document and begin a Transaction
myDWG = ApplicationServices.Application.DocumentManager.MdiActiveDocument
myTransMan = myDWG.TransactionManager
myTrans = myTransMan.StartTransaction
'Open the BlockTable for Read
myBT = myDWG.Database.BlockTableId.GetObject( _
DatabaseServices.OpenMode.ForRead)
myBTR = myBT(DatabaseServices.BlockTableRecord.ModelSpace).GetObject( _
DatabaseServices.OpenMode.ForWrite)
'Draw the line
Dim StartPoint As New Geometry.Point3d(0, 0, 0)
Dim EndPoint As New Geometry.Point3d(4, 5, 6)
Dim myLine As New DatabaseServices.Line(StartPoint, EndPoint)
myBTR.AppendEntity(myLine)
myTrans.AddNewlyCreatedDBObject(myLine, True)
'Commit the Transaction
myTrans.Commit()
myTrans.Dispose()
myTransMan.Dispose()
End Sub
my C# hack
[CommandMethod("Cmd1")]
static public void AddLineToModelSpace()
{
// Calculate the Line extent
Point3d startPoint = new Point3d(1, 2, 3);
Point3d endPoint = new Point3d(4, 5, 6);
// Start a Drawing DataBase Transaction
Database db = AcadApp.DocumentManager.MdiActiveDocument.Database;
using (Transaction tr = db.TransactionManager.StartTransaction())
{
// Define the Line
Line lineEnt = new Line(startPoint, endPoint);
((BlockTableRecord)tr.GetObject(SymbolUtilityServices.GetBlockModelSpaceId(db),
OpenMode.ForWrite, false)).AppendEntity(lineEnt);
tr.AddNewlyCreatedDBObject(lineEnt, true);
tr.Commit();
}
}
Now I'm sure the VB code could be trimmed, but why wasn't it ?