Author Topic: Initget and getpoint  (Read 1486 times)

0 Members and 1 Guest are viewing this topic.

civil.eng

  • Newt
  • Posts: 66
Initget and getpoint
« on: June 11, 2021, 03:17:27 AM »
Hi all, I'm going to use initget and getpoint so that getpoint is repeated only one time at first time, I wrote these codes after trying several ways and this is working but it exits the program after exiting the loop :
Code: [Select]
(setq k 1)
(initget "Setting")
(setq gtpt (getpoint "\nPick a point to add lable [Setting]: "))

(cond
    ((/= gtpt "Setting")

(setq pt gtpt)
     
(while (listp pt)

(maketxt
       pt
       (atoi (getenv "sizetx"))
       (itoa k)
       (atoi (getenv "colornum"))
     )

     (lstadd pt (itoa k))

  (setq pt (getpoint "\nPick a point to add lable : "))
  (setq k (1+ k)))

     ))

BIGAL

  • Swamp Rat
  • Posts: 1392
  • 40 + years of using Autocad
Re: Initget and getpoint
« Reply #1 on: June 11, 2021, 07:42:42 PM »
Not sure what your trying to do an example of picking points and making a list. You ask is "setting" if not skip ? do you have different values that you want and do other functions if so use a (Cond and run say a defun for "settings" no need for while where you have it.

Code: [Select]
(setq lst '())
(while (setq pt (getpoint "\nPick pt Enter to exit"))
(setq lst (cons pt lst))
)

Post a dwg or a image to explain.

« Last Edit: June 11, 2021, 07:46:46 PM by BIGAL »
A man who never made a mistake never made anything

civil.eng

  • Newt
  • Posts: 66
Re: Initget and getpoint
« Reply #2 on: June 13, 2021, 05:26:01 AM »
Thank you for replying. this was helpful :

Code: [Select]
(setq lst '())
(while (setq pt (getpoint "\nPick pt Enter to exit"))
(setq lst (cons pt lst))
)

ronjonp

  • Needs a day job
  • Posts: 7524
Re: Initget and getpoint
« Reply #3 on: June 14, 2021, 12:01:02 PM »
Thank you for replying. this was helpful :

Code: [Select]
(setq lst '())
(while (setq pt (getpoint "\nPick pt Enter to exit"))
(setq lst (cons pt lst))
)
FWIW this works as well:
Code - Auto/Visual Lisp: [Select]
  1. (while (setq pt (getpoint "\nPick pt Enter to exit"))
  2. (setq lst (cons pt lst))
  3. )

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

JohnK

  • Administrator
  • Seagull
  • Posts: 10595
Re: Initget and getpoint
« Reply #4 on: June 14, 2021, 01:25:46 PM »
Also FWIW, you can keep the user from misspicks...
Code - Auto/Visual Lisp: [Select]
  1. (defun vl-getpoin7 ( / x )
  2.     (setq x
  3.      (vl-catch-all-apply 'vla-getpoint
  4.       (list (vla-get-utility
  5.              (vlax-get-property
  6.               (vlax-get-acad-object)
  7.               'ActiveDocument))
  8.              nil
  9.              "\nPick a point: "))
  10.      )
  11.    )
  12.  )
  13. )

Code - Auto/Visual Lisp: [Select]
  1. (defun getpoin7 ( / x)
  2.   (while (not (setq x (getpoint "\nPick a point: ")))
  3.          (princ "\nYou missed, try again."))
  4.   x
  5.   )
TheSwamp.org (serving the CAD community since 2003)
Member location map - Add yourself

Donate to TheSwamp.org

JohnK

  • Administrator
  • Seagull
  • Posts: 10595
Re: Initget and getpoint
« Reply #5 on: June 14, 2021, 03:12:43 PM »
TheSwamp.org (serving the CAD community since 2003)
Member location map - Add yourself

Donate to TheSwamp.org

JohnK

  • Administrator
  • Seagull
  • Posts: 10595
Re: Initget and getpoint
« Reply #6 on: June 14, 2021, 03:35:10 PM »
This one was also a favorite of mine that gave a point list (fits more into the OPs orig line of questioning).

Code - Auto/Visual Lisp: [Select]
  1. (defun points (/ plst pt p1 sp cnt)
  2.   ;;===================================================================;
  3.   ;; Smadsens function for getting points and generating a list of     ;
  4.   ;; points.                                                           ;
  5.   ;;===================================================================;
  6.   (cond ((setq pt (getpoint "\nStart point: "))
  7.          (setq plst (cons pt plst)
  8.                p1   pt
  9.                sp   pt
  10.                cnt  2)))
  11.   (while pt
  12.          (initget "Close")
  13.          (setq pt (getpoint p1 (strcat "\nGimme point no. " (itoa cnt) ": ")))
  14.          (cond ((vl-consp pt)(grdraw p1 pt 2)
  15.                 (setq plst (cons pt plst) p1 pt))
  16.                ((= pt "Close")(grdraw p1 sp 2)
  17.                 (setq pt sp plst (cons pt plst) pt nil))
  18.                )
  19.          (setq cnt (1+ cnt))
  20.          )
  21.   (reverse plst)
  22. )

and/or this one (also by SMadsen).
Code - Auto/Visual Lisp: [Select]
  1. (defun getpointy (pt / ans)
  2.   (if (= cntr nil)
  3.     (setq cntr 1))
  4.   (cond
  5.     ((setq ans (if pt (getpoint pt "\nSpecify point: ")
  6.                  (getpoint "\nSpecify point: ")))
  7.      (cond ((and ans pt)
  8.             (setq PointList (cons pt PointList)
  9.                   cntr      (1+ cntr))
  10.             (grdraw pt ans 2)
  11.             )
  12.            )
  13.      (getpointy ans)
  14.      )
  15.     )
  16.   PointList
  17. )
  18.  
  19. (defun getPoints (/ PointList cntr)
  20.   (defun getpointy (pt / ans)
  21.     (cond ((setq ans (if pt (getpoint pt "\nSpecify point: ")
  22.                             (getpoint "\nSpecify point: ")))
  23.            (setq PointList (cons ans PointList))
  24.            (if pt (grdraw pt ans 4 1))
  25.            (getpointy ans)
  26.           )
  27.     )
  28.     (reverse PointList)
  29.   );_ end defun
  30.   (setq PointList (getpointy nil))
  31.   Pointlist
  32. )

I also generated a point list in a slightly different format when I programmed in AutoLisp full time, in that, I kept a pick number along with the point (but these are not as easy to work with though; for example these are formatted in "start/end" style so using grdraw and "undo" was easy to deal with but odd number of points were more of a problem to account for).
-e.g.
Code: [Select]
((1 ((2.93876 1.86267 0.0) (2.35364 3.00116 0.0)))
 (2 ((2.35364 3.00116 0.0) (2.47902 4.04565 0.0)))
 (3 ((2.47902 4.04565 0.0) (3.21043 5.16325 0.0))) )
TheSwamp.org (serving the CAD community since 2003)
Member location map - Add yourself

Donate to TheSwamp.org