Command: (getpoint "\nPlease pick a point: ")
Please pick a point: 0,0
(0.0 0.0 0.0)
(initget 128)
(if (setq p (getpoint "Point or number: "))
(if (listp p)
p
(read p)
)
)
(defun Waitcom () (while (> (getvar "cmdactive") 0) (command pause)) ) ; subroutine
(defun c:RR ( / p1 p2 x1 y1 inp1)
(setq p1 (getpoint "First corner of Rectangle: "))
; second input can be either a point (2nd corner) or a number (width)
(initget 129) ; bit 7 allows arbitrary input as if it is a keyword
; if bits 7 and 0 are set and the user presses Enter, a null string is returned.
(if (setq inp2 (getcorner p1 "Second corner or width: ")) (progn
;----if there's any input in response to getpoint, continue
(if (listp inp2)
;----test whether the input is a list, i.e. a point rather than a single number
(progn ;----start of the Then expression
(setq p2 inp2) ; then the input is the second corner
(command "Rectang" p1 p2) ; draw a rectangle between the two corners
) ;----end of the Then expression
(progn ;----start of the first Else expression
(setq x1 (read inp2)) ; else the first list or atom in the input string is the width
(if x1 ;----test whether the entered width was non-nil
(progn ;----start of the second Then expression
(setq y1 (getreal "Height of Rectangle: ")) ;----then get the height...
(command "Rectang" "D" x1 y1 p1) (Waitcom)
;----and draw a rectangle by width/height/point
) ;----end of the second Then expression
(progn ; beginning of the second Else expression:
; if not non-nil, then the input was just Enter
(command "Rectang" p1) (Waitcom) ;----else draw a rectangle from p1
) ;----end of the second Else expression
) ;----end of If the entered width was non-nil
) ;----end of the first Else expression
) ;----end (if) the input is a point
)) ;----end (if) there was any input at all and its progn
(sssetfirst nil (ssget "L"))
) ;----end defun
edited: second (getpoint) changed to (getcorner p1); subroutine added
(defun C:test ( / 3Dpt->2Dpt _drawrec L p bbox )
(setq 3Dpt->2Dpt (lambda (p) (mapcar '(lambda (x) (nth x p)) '(0 1))))
(setq _drawrec (lambda (L) (redraw) (apply ''((a b c d) (foreach x '((a b)(b c)(c d)(d a)) (eval (append '(grdraw) x '(1 1))))) L)))
(and
(setq L
(CycleInputs
'(
(p1 (progn (initget "Exit") (if (and w h p2) "Exit" (eval (append (if p2 '(getcorner p2) '(getpoint)) '("\nSpecify first point [Exit] <Next Input>: "))))))
(p2 (progn (initget "Exit") (if (and w h p1) "Exit" (eval (append (if p1 '(getcorner p1) '(getpoint)) '("\nSpecify second point [Exit] <Next Input>: "))))))
(w (progn (initget "Exit") (if (and p1 p2) "Exit" (getreal "\nInput width [Exit] <Next Input>: "))))
(h (progn (initget "Exit") (if (and p1 p2) "Exit" (getreal "\nInput height [Exit] <Next Input>: "))))
)
(lambda (sym val) (= "Exit" val) )
); CycleInputs
)
(cond
( (apply 'and (setq bbox (mapcar 'cdr (list (assoc 'p1 L) (assoc 'p2 L)))))
(setq bbox (mapcar '3Dpt->2Dpt bbox))
)
( (vl-some '(lambda (x) (setq p (cdr (assoc x L)))) '(p1 p2))
(setq bbox (list (3Dpt->2Dpt p) (mapcar '+ (mapcar '(lambda (x) (cdr (assoc x L))) '(w h)) p)))
)
); cond
(_drawrec (LM:BBox->List bbox))
); and
(princ)
); defun C:test
; Grrr
; Cycles the prompts for the user's inputs
; inpL - assoc list of inputs [CAR = symbol to bound] [CADR = evaluation]
; exitf - exit function for the user
; Returns assoc list with the successful inputs, with the symbols unbounded
; NOTE: the returned input list might be partial - so length check comparsion might be required, when used
(defun CycleInputs ( inpL exitf / tmp )
(cond ; (87 114 105 116 116 101 110 32 98 121 32 71 114 114 114)
( (not inpL) inpL)
( (setq tmp (vl-catch-all-apply (function (lambda (a b) (set a (eval b)))) (car inpL))) ; bound the symbols in the input list
(cond
( (vl-catch-all-error-p tmp) (prompt (vl-catch-all-error-message tmp)) )
( (and exitf (vl-catch-all-apply (function exitf) (list (caar inpL) tmp))) (set (caar inpL) nil) ) ; Exiting, unbound the last symbol
(
(mapcar (function (lambda (tmp) (set (car tmp) nil) tmp)) ; unbound the symbols from the input list
(cons (cons (caar inpL) tmp) (CycleInputs (cdr inpL) exitf)) ; store the successful input and go to the next one
)
)
); cond
)
( (CycleInputs (reverse (cons (car inpL) (reverse (cdr inpL)))) exitf) ) ; Else, shift to the next input and store the failed as last one
); cond
); defun CycleInputs
;;----------------=={ BoundingBox -> List }==-----------------;;
;; ;;
;; Returns the coordinates of a rectangle from the ;;
;; coordinates of the lower-left and upper-right corners ;;
;;------------------------------------------------------------;;
;; Author: Lee Mac, Copyright © 2010 - www.lee-mac.com ;;
;;------------------------------------------------------------;;
;; Arguments: ;;
;; bbox - list of lower-left and upper-right coordinates ;;
;;------------------------------------------------------------;;
;; Returns: coordinates of rectangle ;;
;;------------------------------------------------------------;;
(defun LM:BBox->List ( bbox )
(mapcar
(function
(lambda ( funcs )
(mapcar
(function
(lambda ( func ) ((eval func) bbox))
)
funcs
)
)
)
'((caar cadar) (caadr cadar) (caadr cadadr) (caar cadadr))
)
)
Is there any way to prompt for a numeric input OR a point, <<<<
I want to prompt for a second point, either by picking the second point or by entering X- and Y-coordinates of the offset from the first point. <<<<