Jump to content

Help with Palette


Hippe013

Recommended Posts

Hello everyone!

 

I am very familiar with VLISP, but extremely new to vb.NET. I am trying to write a simple measuring tool to display the results to a palette.

 

 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

 

What I am finding is that when I run 'NEWAX' the palette is displayed but it then cancels my command. When I rerun the command it continues as I expected. So far I have only written what happens when the user cancels after selecting the first point. This part works and I will fill in the gaps later. The trouble is that it cancels the command if the palette isn't displayed. Any help is appreciated & if you care to comment and give pointers on the rest of the code that is welcome as well.

 

regards,

 

Hippe013

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...