<CommandMethod("jhl")> _
Public Sub TestLine()
Dim toto As New Line
Dim p1 As New Point3d(0, 0, 0)
Dim p2 As New Point3d(100, 100, 0)
toto = CreateLine(p1, p2)
End Sub

 

 

 


Shared Function CreateLine(ByVal PtStart As Autodesk.AutoCAD.Geometry.Point3d, ByVal PtEnd As Autodesk.AutoCAD.Geometry.Point3d) As Autodesk.AutoCAD.DatabaseServices.Line
Dim acDoc As Document = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument
Dim acCurDb As Database = acDoc.Database
Dim acline As New Line
'' 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, OpenMode.ForRead)

    '' Open the Block table record Model space for write
    Dim acBlkTblRec As BlockTableRecord
    acBlkTblRec = acTrans.GetObject(acBlkTbl(BlockTableRecord.ModelSpace), OpenMode.ForWrite)

    '' Create a line with PtStart and PtEnd
    acline.StartPoint = PtStart
    acline.EndPoint = PtEnd
    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
CreateLine = acline
End Function