这样就可以提示用户输入点坐标了。
Imports Autodesk.AutoCAD.ApplicationServices Imports Autodesk.AutoCAD.EditorInput Imports Autodesk.AutoCAD.Runtime Imports Autodesk.AutoCAD.DatabaseServices Imports Autodesk.AutoCAD.Colors Imports Autodesk.AutoCAD.Geometry Imports Autodesk.AutoCAD.GraphicsInterface Imports DBTransMan = Autodesk.AutoCAD.DatabaseServices.TransactionManager
Public Class Class1
<CommandMethod("MyLine")> Public Function Myline() Dim db As Database = HostApplicationServices.WorkingDatabase() Dim myT As Transaction = db.TransactionManager.StartTransaction() Dim x1, y1, z1, x2, y2, z2 As Single Try Dim prPointOptions As PromptPointOptions = New PromptPointOptions("指定起点:") Dim prPointRes As PromptPointResult Dim ed As Editor = Application.DocumentManager.MdiActiveDocument.Editor prPointRes = ed.GetPoint(prPointOptions) If prPointRes.Status <> PromptStatus.OK Then ed.WriteMessage("你选择的点无效,请重新选择!") Else ed.WriteMessage("起点: " & prPointRes.Value.ToString()) x1 = prPointRes.Value.X y1 = prPointRes.Value.Y z1 = prPointRes.Value.Z End If Dim prPointOptions1 As PromptPointOptions = New PromptPointOptions("指定终点:") prPointRes = ed.GetPoint(prPointOptions1) If prPointRes.Status <> PromptStatus.OK Then ed.WriteMessage("你选择的点无效,请重新选择!") Else ed.WriteMessage("终点: " & prPointRes.Value.ToString()) x2 = prPointRes.Value.X y2 = prPointRes.Value.Y z2 = prPointRes.Value.Z End If Dim line As Line = New Line(New Point3d(x1, y1, z1), New Point3d(x2, y2, z2)) Dim bt As BlockTable = CType(myT.GetObject(db.BlockTableId, OpenMode.ForRead, False), BlockTable) Dim btr As BlockTableRecord = CType(myT.GetObject(bt(BlockTableRecord.ModelSpace), OpenMode.ForWrite, False), BlockTableRecord) btr.AppendEntity(line) myT.AddNewlyCreatedDBObject(line, True) myT.Commit() Catch Finally myT.Dispose() End Try End Function
End Class |