creating a line between two points

creating a line between two points

Anonymous
Not applicable
4,206 Views
4 Replies
Message 1 of 5

creating a line between two points

Anonymous
Not applicable

Hi,

 

All I have done till now is quite basic VB.net stuff

 

I would like to get more advanced and creative with my creations. basically when i think AutoCAD i think lines so a nice short program to get started with is to create a line between two point (or simular). The tutorials online are wofel in learning the basics such as this is anyone out there able to give me a few starters on how to achive this

0 Likes
4,207 Views
4 Replies
Replies (4)
Message 2 of 5

norman.yuan
Mentor
Mentor

Have you gone through Autodesk provided .NET programming labs? Have you gone through AutoCAD .NET Developer's Guid online (http://docs.autodesk.com/ACD/2010/ENU/AutoCAD%20.NET%20Developer's%20Guide/index.html)?

 

Anyway, here's some quick code (without actually running/testing in VS):

 

Dim pt1 As New Point3d(0.0,0.0,0.0)

Dim pt2 As New Point3d(1.0,1.0,0.0)

 

''A new line entity is created

Dim myLime As New Line(pt1, pt2)

 

''Set the line's properties,such as layer, linetype...to default

myLine.SetDatabaseDefault()

 

''Do something with the line

 

''If you do not want to add it to the current drawing database,

''you need to dispose it after you done whth it

'myLine.Dispose()

 

''Add it to current drawing database, modelspace

Dim db As Database=HostApplicationServices.WorkingDatabase

Using tran as Transaction=db.TransactionMananer.StartTransaction()

  ''Open Block Table

  Dim bt As BlockTable=tran.GetObject(db.BlockTableId,OpenMode.ForRead)

  ''Open modelspace

  Dim model As BlockTableRecord=tran.GetObject(bt(BlockTablerecord.ModeSpace),OpenMode.ForWrite)

  ''Add myLine to ModelSpace

  mode.AppendEntity(myLine)

  ''register the new entity with the transaction

  tran.AddNewLyCreatedDbObject(myLine,True)

  ''Complete the transaction

  tran.Commit()

End Using

 

HTH

Norman Yuan

Drive CAD With Code

EESignature

0 Likes
Message 3 of 5

chiefbraincloud
Collaborator
Collaborator

I suggest Kean Walmsley's blog.  He has been posting for almost 5 years know, and there is a wealth of information in the archives.

 

the first post is here:

 

http://through-the-interface.typepad.com/through_the_interface/2006/06/welcome.html

Dave O.                                                                  Sig-Logos32.png
0 Likes
Message 4 of 5

Anonymous
Not applicable

Jerry Winters has a good book on vb.net programming. Also Autocad University Online has tons of information and tutorials.

 

 

Dave

0 Likes
Message 5 of 5

mgorecki
Collaborator
Collaborator

I'm just learning too.  This is what I use.

 

CreateLines(lineStartPt, lineEndPt, linetypeName)

 

 

Public Sub CreateLines(ByVal startPoint As Point3d, ByVal endPoint As Point3d, ByVal linetypeName As String)
        ' Get the current document and database
        Dim podDoc As Document = Application.DocumentManager.MdiActiveDocument
        Dim podCurDb As Database = podDoc.Database

        ' Start a transaction 
        Using podTrans As Transaction = podCurDb.TransactionManager.StartTransaction()

            ' Open the Linetype table for read
            Dim acLineTypTbl As LinetypeTable
            acLineTypTbl = podTrans.GetObject(podCurDb.LinetypeTableId, OpenMode.ForRead)

            ' If the linetype has not been loaded, then load it
            If acLineTypTbl.Has(linetypeName) = False Then
                '' Load the Center Linetype
                podCurDb.LoadLineTypeFile(linetypeName, "acad.lin")
            End If

            ' Open the Block table for read
            Dim podBlkTbl As BlockTable
            podBlkTbl = podTrans.GetObject(podCurDb.BlockTableId, OpenMode.ForRead)

            ' Open the Block table record Model space for write
            Dim podBlkTblRec As BlockTableRecord
            podBlkTblRec = podTrans.GetObject(podBlkTbl(BlockTableRecord.ModelSpace), OpenMode.ForWrite)

            ' Create the lines
            Dim newLine As New DatabaseServices.Line(startPoint, endPoint)
            newLine.SetDatabaseDefaults()

            Select Case linetypeName
                Case "Continuous"
                    newLine.Linetype = "Continuous"
                Case "Dashed"
                    newLine.Linetype = "Dashed"
                Case "Phantom"
                    newLine.Linetype = "Phantom"
            End Select

            podBlkTblRec.AppendEntity(newLine)
            podTrans.AddNewlyCreatedDBObject(newLine, True)

            ' Save the changes and dispose of the transaction
            podTrans.Commit()
        End Using
    End Sub

0 Likes