大家好!
我非常熟悉VLISP,但对vb非常陌生。净额。我正在尝试编写一个简单的测量工具,将结果显示在调色板上。
- 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
我发现,当我运行“NEWAX”时,会显示调色板,但它会取消我的命令。当我重新运行该命令时,它会像我预期的那样继续。到目前为止,我只写了当用户选择第一个点后取消时会发生什么。这部分很有效,稍后我将填补空白。问题是,如果调色板没有显示,它会取消该命令。如果您愿意对代码的其余部分进行评论和指点,我们将不胜感激。
当做
Hippe013 |