.NET
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Connectd Lines and Arcs

2 REPLIES 2
Reply
Message 1 of 3
albazel2004
391 Views, 2 Replies

Connectd Lines and Arcs

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

2 REPLIES 2
Message 2 of 3
Hallex
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
Message 3 of 3
BKSpurgeon
in reply to: Hallex

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk DevCon in Munich May 28-29th


Autodesk Design & Make Report

”Boost