乐筑天下

搜索
欢迎各位开发者和用户入驻本平台 尊重版权,从我做起,拒绝盗版,拒绝倒卖 签到、发布资源、邀请好友注册,可以获得银币 请注意保管好自己的密码,避免账户资金被盗
查看: 55|回复: 0

[编程交流] 调色板帮助

[复制链接]

20

主题

338

帖子

323

银币

初露锋芒

Rank: 3Rank: 3Rank: 3

铜币
100
发表于 2022-7-6 21:57:36 | 显示全部楼层 |阅读模式
大家好!
 
我非常熟悉VLISP,但对vb非常陌生。净额。我正在尝试编写一个简单的测量工具,将结果显示在调色板上。
 
  1. Imports System.Runtime
  2. Imports Autodesk.AutoCAD.Runtime
  3. Imports Autodesk.AutoCAD.ApplicationServices
  4. Imports Autodesk.AutoCAD.DatabaseServices
  5. Imports Autodesk.AutoCAD.Geometry
  6. Imports Autodesk.AutoCAD.EditorInput
  7. ' This line is not mandatory, but improves loading performances
  8. <Assembly: CommandClass(GetType(AutoCAD_VB_plug_in1.MyCommands))>
  9. Namespace AutoCAD_VB_plug_in1
  10.    Public Class MyCommands
  11.        Public ed As Editor = Application.DocumentManager.MdiActiveDocument.Editor
  12.        'Polar Function
  13.        Public Shared Function polar(ByVal p0 As Point3d, ByVal ang As Double, ByVal dist As Double)
  14.            Return New Point3d(p0.X + dist * Math.Cos(ang), _
  15.                               p0.Y + dist * Math.Sin(ang), _
  16.                               p0.Z)
  17.        End Function
  18.        'Drawx Function
  19.        Public Sub drawX(ByVal p0 As Point3d, ByVal clr As Integer)
  20.            Dim vs As Double = (Application.GetSystemVariable("VIEWSIZE") / 40.0)
  21.            Dim p1 As Point3d = polar(p0, (Math.PI * 0.25), vs)
  22.            Dim p2 As Point3d = polar(p0, (Math.PI * 0.75), vs)
  23.            Dim p3 As Point3d = polar(p0, (Math.PI * 1.25), vs)
  24.            Dim p4 As Point3d = polar(p0, (Math.PI * 1.75), vs)
  25.            ed.DrawVector(p0, p1, clr, False)
  26.            ed.DrawVector(p0, p2, clr, False)
  27.            ed.DrawVector(p0, p3, clr, False)
  28.            ed.DrawVector(p0, p4, clr, False)
  29.        End Sub
  30.        Friend Shared m_ps As Autodesk.AutoCAD.Windows.PaletteSet = Nothing
  31.        Friend Shared mypalette As UserControl1 = New UserControl1()
  32.        <CommandMethod("NewAX")> _
  33.        Public Sub NewAX()
  34.            If m_ps Is Nothing Then
  35.                m_ps = New Autodesk.AutoCAD.Windows.PaletteSet("My Palette")
  36.                m_ps.Add("My Palette", mypalette)
  37.            End If
  38.            If m_ps.Visible = False Then
  39.                m_ps.Visible = True
  40.            End If
  41.            pickpoints()
  42.        End Sub
  43.        Public Sub pickpoints()
  44.            Dim opt As PromptPointOptions = New PromptPointOptions("")
  45.            opt.Message = vbCrLf & "Select First Point: "
  46.            Dim ret As PromptPointResult
  47.            ret = ed.GetPoint(opt)
  48.            If ret.Status = PromptStatus.OK Then
  49.                Dim p0 As Point3d = ret.Value
  50.                drawX(p0, 2)
  51.                opt.Message = vbCrLf & "Select Second Point: "
  52.                opt.BasePoint = p0
  53.                opt.UseBasePoint = True
  54.                ret = ed.GetPoint(opt)
  55.                If ret.Status = PromptStatus.OK Then
  56.                    Dim p1 As Point3d = ret.Value
  57.                    drawX(p1, 2)
  58.                Else
  59.                    Dim p0X As Double = p0.X
  60.                    Dim p0Y As Double = p0.Y
  61.                    Dim p0Z As Double = p0.Z
  62.                    mypalette.Label1.Text = "Northing: " & p0Y.ToString("N3")
  63.                    mypalette.Label2.Text = "Easting: " & p0X.ToString("N3")
  64.                    mypalette.Label3.Text = "Elevation: " & p0Z.ToString("N3")
  65.                End If
  66.            End If
  67.        End Sub
  68.    End Class
  69. End Namespace

 
我发现,当我运行“NEWAX”时,会显示调色板,但它会取消我的命令。当我重新运行该命令时,它会像我预期的那样继续。到目前为止,我只写了当用户选择第一个点后取消时会发生什么。这部分很有效,稍后我将填补空白。问题是,如果调色板没有显示,它会取消该命令。如果您愿意对代码的其余部分进行评论和指点,我们将不胜感激。
 
当做
 
Hippe013
回复

使用道具 举报

发表回复

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

  • 微信公众平台

  • 扫描访问手机版

  • 点击图片下载手机App

QQ|关于我们|小黑屋|乐筑天下 繁体中文

GMT+8, 2025-3-4 13:18 , Processed in 0.349160 second(s), 54 queries .

© 2020-2025 乐筑天下

联系客服 关注微信 帮助中心 下载APP 返回顶部 返回列表