Imports System.Runtime
Imports Autodesk.AutoCAD.Runtime
Imports Autodesk.AutoCAD.ApplicationServices
Imports Autodesk.AutoCAD.DatabaseServices
Imports Autodesk.AutoCAD.Geometry
Imports Autodesk.AutoCAD.EditorInput
' This line is not mandatory, but improves loading performances
<Assembly: CommandClass(GetType(AutoCAD_VB_plug_in1.MyCommands))>
Namespace AutoCAD_VB_plug_in1
Public Class MyCommands
Public ed As Editor = Application.DocumentManager.MdiActiveDocument.Editor
'Polar Function
Public Shared Function polar(ByVal p0 As Point3d, ByVal ang As Double, ByVal dist As Double)
Return New Point3d(p0.X + dist * Math.Cos(ang), p0.Y + dist * Math.Sin(ang), p0.Z)
End Function
'Drawx Function
Public Sub drawX(ByVal p0 As Point3d, ByVal clr As Integer)
Dim vs As Double = (Application.GetSystemVariable("VIEWSIZE") / 40.0)
Dim p1 As Point3d = polar(p0, (Math.PI * 0.25), vs)
Dim p2 As Point3d = polar(p0, (Math.PI * 0.75), vs)
Dim p3 As Point3d = polar(p0, (Math.PI * 1.25), vs)
Dim p4 As Point3d = polar(p0, (Math.PI * 1.75), vs)
ed.DrawVector(p0, p1, clr, False)
ed.DrawVector(p0, p2, clr, False)
ed.DrawVector(p0, p3, clr, False)
ed.DrawVector(p0, p4, clr, False)
End Sub
Friend Shared m_ps As Autodesk.AutoCAD.Windows.PaletteSet = Nothing
Friend Shared mypalette As UserControl1 = New UserControl1()
<CommandMethod("NewAX")>
Public Sub NewAX()
If m_ps Is Nothing Then
m_ps = New Autodesk.AutoCAD.Windows.PaletteSet("My Palette")
m_ps.Add("My Palette", mypalette)
End If
If m_ps.Visible = False Then
m_ps.Visible = True
End If
pickpoints()
End Sub
Public Sub pickpoints()
Dim opt As PromptPointOptions = New PromptPointOptions("")
opt.Message = vbCrLf & "Select First Point: "
Dim ret As PromptPointResult
ret = ed.GetPoint(opt)
If ret.Status = PromptStatus.OK Then
Dim p0 As Point3d = ret.Value
drawX(p0, 2)
opt.Message = vbCrLf & "Select Second Point: "
opt.BasePoint = p0
opt.UseBasePoint = True
ret = ed.GetPoint(opt)
If ret.Status = PromptStatus.OK Then
Dim p1 As Point3d = ret.Value
drawX(p1, 2)
Else
Dim p0X As Double = p0.X
Dim p0Y As Double = p0.Y
Dim p0Z As Double = p0.Z
mypalette.Label1.Text = "Northing: " & p0Y.ToString("N3")
mypalette.Label2.Text = "Easting: " & p0X.ToString("N3")
mypalette.Label3.Text = "Elevation: " & p0Z.ToString("N3")
End If
End If
End Sub
End Class
End Namespace