.NET

Reply
New Member
albazel2004
Posts: 1
Registered: ‎12-24-2013
Message 1 of 2 (157 Views)

Connectd Lines and Arcs

157 Views, 1 Replies
12-24-2013 12:39 PM

Using VB.NET

How to draw connected line arc line arc line and so on, given some points formatted in a file like this

easting        northing             radius

0                 0
10               10                      200.00
12               10                      150.00
30               20                      60.00
50               30                      50.00
50               43                      60.00
1640.42      1104.30             50.00
1770.20      1100.62            100.00
1850.00      1085.18            100.00
2002.61      1141.46

 

the output will be like this :

line arc line arc line arc line arc line arc line arc line arc line arc line

*Expert Elite*
Hallex
Posts: 1,569
Registered: ‎10-08-2008
Message 2 of 2 (151 Views)

Re: Connectd Lines and Arcs

12-24-2013 01:51 PM in reply to: albazel2004

You can start from this code, gathered from many autors:

#Region "Select connected lines and arcs"
        <CommandMethod("arclines", CommandFlags.UsePickSet)> _
        Public Sub LoopGetEntity()
            Dim doc As Document = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument
            Dim db As Database = doc.Database
            Dim ed As Editor = doc.Editor
            Dim oids() As ObjectId = GetUserPickedObjects(doc, "Select line or arc one by another: ")
            ed.Regen()
            Dim sb As StringBuilder = New StringBuilder
            Dim txtfile = Path.Combine("C:\Test\", "my_lines_and_arcs.csv") '<-- change directory name and file name here
            Using tr As Transaction = doc.Database.TransactionManager.StartTransaction()
                Dim txtLine As String = ""
                For Each id As ObjectId In oids
                    Dim ent As DBObject = tr.GetObject(id, OpenMode.ForRead, False)
                    If TypeOf (ent) Is Arc Then
                        Dim arc As Arc = TryCast(ent, Arc)
                        If arc Is Nothing Then Return
                        Dim sp As Point3d = arc.StartPoint
                        Dim ep As Point3d = arc.EndPoint
                        Dim rad As Double = arc.Radius
                        txtLine = String.Format("{0:f3}" + vbTab + "{1:f3}" + vbTab + "{2:f3}" + vbTab + "{3:f3}" + vbTab + "{4:f3}", sp.X, sp.Y, ep.X, ep.Y, rad)
                        sb.AppendLine(txtLine)
                    Else
                        Dim ln As Line = TryCast(ent, Line)
                        If ln Is Nothing Then Return
                        Dim sp As Point3d = ln.StartPoint
                        Dim ep As Point3d = ln.EndPoint

                        txtLine = String.Format("{0:f3}" + vbTab + "{1:f3}" + vbTab + "{2:f3}" + vbTab + "{3:f3}" + vbTab + "{4:f3}", sp.X, sp.Y, ep.X, ep.Y, String.Empty)
                        sb.AppendLine(txtLine)
                    End If

                Next
            End Using

            Try
                Using sw As New StreamWriter(txtfile, False, Encoding.Default)
                    sw.Write(sb.ToString())
                    sw.Close()
                End Using
            Catch
            Finally
                System.Diagnostics.Process.Start(txtfile)
            End Try
        End Sub

        Private Shared Function GetUserPickedObjects(ByVal doc As Document, msg As String) As ObjectId()
            Dim ids As New List(Of ObjectId)
            Using tr As Transaction = doc.Database.TransactionManager.StartTransaction()
                Dim go As Boolean = True
                While go
                    go = False

                    Dim opt As New PromptEntityOptions(vbLf & msg)
                    opt.SetRejectMessage(vbLf + "You have to select line or arc only!")
                    opt.AddAllowedClass(GetType(Line), False)
                    opt.AddAllowedClass(GetType(Arc), False)

                    Dim res As PromptEntityResult = doc.Editor.GetEntity(opt)

                    If res.Status = PromptStatus.OK Then
                        Dim exists As Boolean = False
                        For Each id As ObjectId In ids
                            If id = res.ObjectId Then
                                exists = True
                                Exit For
                            End If
                        Next

                        If Not exists Then
                            'Highlight
                            Dim ent As Entity = DirectCast(tr.GetObject(res.ObjectId, OpenMode.ForWrite), Entity)
                            ent.Highlight()
                            ids.Add(res.ObjectId)
                            go = True
                        End If
                    End If
                End While

                tr.Commit()
            End Using
            Return ids.ToArray()
        End Function
#End Region

 

_____________________________________
C6309D9E0751D165D0934D0621DFF27919
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!