Originally Posted by
clintonc
How do you create a polyline with .net starting with a 3d point (user input)? I have found lots of examples of creating plines with hard coded points, but none that start with user input.
Any help would be great.
Here is very easy example not so elegance though
Code:
Imports System
Imports Autodesk.AutoCAD.Runtime
Imports Autodesk.AutoCAD.Geometry
Imports Autodesk.AutoCAD.EditorInput
Imports Autodesk.AutoCAD.DatabaseServices
Imports Autodesk.AutoCAD.GraphicsInterface
Imports Autodesk.AutoCAD.ApplicationServices.Application
Imports AcadRT = Autodesk.AutoCAD.Runtime
Imports AcadED = Autodesk.AutoCAD.EditorInput
Imports AcadDB = Autodesk.AutoCAD.DatabaseServices
Imports AcadApp = Autodesk.AutoCAD.ApplicationServices.Application
Public Class PlineUtils
<CommandMethod("TP")> _
Public Sub InteractPline()
Dim adoc As Autodesk.AutoCAD.ApplicationServices.Document = AcadApp.DocumentManager.MdiActiveDocument
Dim db As Database = adoc.Database
Dim ed As Editor = adoc.Editor
Dim vec As Vector3d = New Vector3d(0, 0, 1).TransformBy(ed.CurrentUserCoordinateSystem)
Dim plane As Plane = New Plane(db.Ucsorg, vec)
Dim res1 As PromptPointResult = ed.GetPoint(ControlChars.CrLf & "Select first point: ")
Dim bp As Point3d = New Point3d(res1.Value.X, res1.Value.Y, res1.Value.Z)
Dim ar As ArrayList = New ArrayList
ar.Add(bp.X)
ar.Add(bp.Y)
Dim res2 As PromptPointResult
Dim n As Integer = 0
Do
Dim opt As PromptPointOptions = New PromptPointOptions(ControlChars.CrLf & "Select next point: ")
opt.AppendKeywordsToMessage = True
opt.UseBasePoint = True
opt.BasePoint = bp
opt.AllowArbitraryInput = True
opt.SetMessageAndKeywords(ControlChars.CrLf & "Select next point: " & "Or Yes to Exit [Y/N]", "Yes No")
res2 = ed.GetPoint(opt)
bp = New Point3d(res2.Value.X, res2.Value.Y, res2.Value.Z)
ar.Add(bp.X)
ar.Add(bp.Y)
n += 1
Loop Until res2.Status = PromptStatus.Keyword
Dim Pline As Polyline = New Polyline(n)
For i As Integer = 0 To ar.Count - 1 Step 2
Pline.AddVertexAt(0, New Point2d(ar(i), ar(i + 1)), 0.0, 0.0, 0.0)
Next i
Pline.Normal = vec
Pline.RemoveVertexAt(0)
Using tr As Transaction = db.TransactionManager.StartTransaction()
Dim btr As BlockTableRecord = CType(tr.GetObject(db.CurrentSpaceId, OpenMode.ForWrite), BlockTableRecord)
btr.AppendEntity(Pline)
tr.AddNewlyCreatedDBObject(Pline, True)
tr.Commit()
End Using
End Sub
Guess, you might want to search for Jig entity examples in AU docs
as well
~'J'~