Author Topic: using keydown with enter key in a while loop  (Read 2079 times)

0 Members and 1 Guest are viewing this topic.

drawworkhome

  • Guest
using keydown with enter key in a while loop
« on: August 15, 2013, 07:19:58 PM »
hi there!
i am new (very new) and am trying to test if the user presses the enter key in a while loop.  the command is being started using netload in autoad (using acad 2012 and vs2010 express).  the end result i am looking for is to have the user draw x amount of polylines (trying to mimic the pline command in this aspect) and if the user hits enter, then exit the sub.  there is no user form.  i believe i have to import the system.windows.forms so i can access the keycode.  i think my question is is how do i make it accessable if i dont have an object to tie it to?  suggestions please?

something like:                  While Not Keys.Enter
                                              'prompt for next points
                                                  Select Case ncounter
                               

n.yuan

  • Bull Frog
  • Posts: 348
Re: using keydown with enter key in a while loop
« Reply #1 on: August 16, 2013, 09:53:12 AM »
Well, since you are programming for AutoCAD, you should make your program behave the way AutoCAD user expects. Every AutoCAD user should know by instinct that hitting "Esc" break/cancel current command/operation. He/she also expects to see a set of keywords being presented as choice of next step, with a logical default keyword is set (e.g. by hitting "Enter" the default keyword is selected).

In your case, if you want you keep picking points until user either hit Esc to jump out the loop and throw away the picked points, or choose a keyword to do different thing other than picking point while still stay in the loop, or choose a default keyword (hitting Enter) to indicate point picking is completed, you only need to use PromptPointOptions and added a default keyword, something like "Done". In conjunction with the prompt message, during the loop, user would see something at command line like this:

Pick next point [Otherkeword/eXit]/<eXit>:

You then examine in the returned PromptPointresult to decide what is user input: point picked, or Esc pressed, or keyword pressed, in which pressing Enter means keyword "eXit", and you can continue or break out the loop accordingly.

There is really no need to get KeyCode using System.Windows.Forms space.

fixo

  • Guest
Re: using keydown with enter key in a while loop
« Reply #2 on: August 16, 2013, 10:54:07 AM »
                       
Here is what Norman had suggested:
Code: [Select]
        <CommandMethod("pps")> _
        Public Sub testMultiplePoints()
            Dim doc As Document = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument
            Dim db As Database = doc.Database
            Dim ed As Editor = doc.Editor
            Using tr As Transaction = db.TransactionManager.StartTransaction()
                Dim pts As New Point3dCollection()
                Dim msg As String = vbLf & "Pick first point: "
                Dim pt As New Point3d()
                Dim ppo As New PromptPointOptions(msg)
                ppo.AllowNone = True
                Dim res As PromptPointResult
                Dim usept As Boolean = False
                Do
                    ppo.UseBasePoint = usept
                    res = ed.GetPoint(ppo)
                    ed.WriteMessage(vbLf + res.Status.ToString())
                    If res.Status = PromptStatus.OK Then
                        pt = res.Value
                        pts.Add(pt)
                    End If

                    usept = True
                    ppo.BasePoint = pt
                    msg = vbLf & "Pick next point: "
                    ppo.Message = msg
                Loop While res.Status = PromptStatus.OK
                ' display result:
                For Each pp As Point3d In pts
                    ed.WriteMessage(vbLf & "{0:f3}", pp)
                Next
                '   ---     here you can create polyline from points    ---     '
                tr.Commit()
            End Using
        End Sub
Thanks to Norman,
Regards

drawworkhome

  • Guest
Re: using keydown with enter key in a while loop
« Reply #3 on: August 18, 2013, 01:05:59 PM »
thank you both for your input and advice