leong1221 发表于 2022-7-5 15:46:22

Getpoint & repeat

Hi Guys,
 
I am writing a lisp using Getpoint (mouse input) and sometime i need 1 point sometime 2 sometime 3 and setq each point to pt1 pt2 pt3.
 
If i want to make this lisp keep asking Getpoint until user press the spacebar to proceed to next step, should i use repeat??

Tharwat 发表于 2022-7-5 16:12:09

Hi,
You can use While function.
 

(while (setq pt (getpoint "\nSpecify a point :")) (setq pts (cons pt pts)))

Aftertouch 发表于 2022-7-5 16:24:44

Check out this tutorail:
 
http://www.afralisp.net/autolisp/tutorials/program-looping.php
 
Exactly this question is explained there..

PDuMont 发表于 2022-7-5 16:38:55

This will assign to a variable pt1, pt2, pt3 etc until enter/spacebar is pressed.
 

(defun c:loop2 (/ pt ptlist cnt num) (setq ptlist nil) (while (setq pt (getpoint "\nEnter Point or RETURN when done: "))   (append ptlist (list pt))) ) ;_ end of while (setq cnt (length ptlist)) (setq num (+ cnt 1)) (repeat cnt   (set (read (strcat "pt" (itoa (setq num (- num 1))))) (last ptlist))   (setq ptlist (vl-remove (last ptlist) ptlist)) ) ;_ end of repeat (princ)) ;_ end of defun

Grrr 发表于 2022-7-5 16:55:25

Recursive:

; (getpoints nil "\n>>> Specify point: ")(defun getpoints ( p m ) (cond ((not (setq p (apply 'getpoint (append (if p (list p)) (if m (list m)))))) p) ((cons p (getpoints p m))))); defun getpoints
页: [1]
查看完整版本: Getpoint & repeat