.NET

Reply
Active Contributor
gulzar25
Posts: 42
Registered: ‎07-02-2013
Message 1 of 3 (178 Views)
Accepted Solution

create line from dbpoints

178 Views, 2 Replies
07-04-2013 10:21 PM

Hi,

How to create line from dbpoints?

Hi, try this sub, it will create a line with default values (layer, line type, etc)

 

Private Sub AddLine(ByVal dbp1 As DBPoint, ByVal dbp2 As DBPoint)
Dim doc As Document = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument
Dim db As Database = HostApplicationServices.WorkingDatabase()
Using acTrans As Transaction = db.TransactionManager.StartTransaction()
Dim acBlkTbl As BlockTable
acBlkTbl = acTrans.GetObject(db.BlockTableId, OpenMode.ForRead)
Dim acBlkTblRec As BlockTableRecord
acBlkTblRec = acTrans.GetObject(acBlkTbl(BlockTableRecord.ModelSpace), OpenMode.ForWrite)
Dim nl As New Line(dbp1.Position, dbp2.Position)
acBlkTblRec.AppendEntity(nl)
acTrans.AddNewlyCreatedDBObject(nl, True)
acTrans.Commit()
End Using
End Sub

 

Gaston Nunez

Distinguished Mentor
gasty1001
Posts: 579
Registered: ‎04-11-2010
Message 2 of 3 (174 Views)

Re: create line from dbpoints

07-04-2013 11:02 PM in reply to: gulzar25

Hi, try this sub, it will create a line with default values (layer, line type, etc)

 

Private Sub AddLine(ByVal dbp1 As DBPoint, ByVal dbp2 As DBPoint)
        Dim doc As Document = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument
        Dim db As Database = HostApplicationServices.WorkingDatabase()

        Using acTrans As Transaction = db.TransactionManager.StartTransaction()
            Dim acBlkTbl As BlockTable
            acBlkTbl = acTrans.GetObject(db.BlockTableId, OpenMode.ForRead)
            Dim acBlkTblRec As BlockTableRecord
            acBlkTblRec = acTrans.GetObject(acBlkTbl(BlockTableRecord.ModelSpace), OpenMode.ForWrite)
            Dim nl As New Line(dbp1.Position, dbp2.Position)
            acBlkTblRec.AppendEntity(nl)
            acTrans.AddNewlyCreatedDBObject(nl, True)
            acTrans.Commit()
        End Using
    End Sub

 

Gaston Nunez

Active Contributor
gulzar25
Posts: 42
Registered: ‎07-02-2013
Message 3 of 3 (166 Views)

Re: create line from dbpoints

07-04-2013 11:23 PM in reply to: gasty1001

HI,

Thanks a lot for the reply it worked.

 

Thankyou so much :smileyhappy:

Gulzar

Post to the Community

Have questions about Autodesk products? Ask the community.

New Post
Announcements
Are You Going To Be @ AU 2014? Feel free to drop by our AU topic post and share your plans, plug a class that you're teaching, or simply check out who else from the community might be in attendance. Ohh and don't forgot to stop by the Autodesk Help | Learn | Collaborate booths in the Exhibit Hall and meet our community team if you get a chance!