Public Sub AddLine(ByVal X1, ByVal Y1, ByVal X2, ByVal Y2)
'' Get the current document and database
Dim acDoc As Document = Application.DocumentManager.MdiActiveDocument
Dim acCurDb As Database = acDoc.Database
'' Start a transaction
Using acTrans As Transaction = acCurDb.TransactionManager.StartTransaction()
'' Open the Block table for read
Dim acBlkTbl As BlockTable
acBlkTbl = acTrans.GetObject(acCurDb.BlockTableId, DatabaseServices.OpenMode.ForRead)
'' Open the Block table record Model space for write
Dim acBlkTblRec As BlockTableRecord
acBlkTblRec = acTrans.GetObject(acBlkTbl(BlockTableRecord.ModelSpace), DatabaseServices.OpenMode.ForWrite)
'' Create a line
Dim acLine As Line = New Line(New Point3d(X1, Y1, 0), New Point3d(X2, Y2, 0))
acLine.SetDatabaseDefaults()
'' Add the new object to the block table record and the transaction
acBlkTblRec.AppendEntity(acLine)
acTrans.AddNewlyCreatedDBObject(acLine, True)
'' Save the new object to the database
acTrans.Commit()
End Using
End Sub
Không có nhận xét nào:
Đăng nhận xét