TheSwamp

Code Red => AutoLISP (Vanilla / Visual) => Topic started by: Mark on August 23, 2004, 12:34:23 PM

Title: (code) Another getreal function
Post by: Mark on August 23, 2004, 12:34:23 PM
Code: [Select]

;;; returns a REAL or NIL
;;; msg = string (prompt for GETREAL)
;;; ibit = integer (for initget)
(defun get-real (msg ibit / trap)
  (initget ibit)
  (setq trap

        (vl-catch-all-apply 'getreal (list msg))
        )

  (cond
    ((vl-catch-all-error-p trap)
     (princ (vl-catch-all-error-message trap)) nil)
    ((not (vl-catch-all-error-p trap)) trap)
    )
  )

;;; example
(defun c:add2 (/ a1 a2 ans)

  (if (setq a1 (get-real ":: " 1))
    (if (setq a2 (get-real ":: " 1))
      (setq ans (+ a1 a2))
      (alert "Cancel Program?"); insert real yes/no dia. here
      )
    (alert "Cancel Program?"); insert real yes/no dia. here
    )

  (if ans (princ (strcat " " (rtos ans))))
  (princ)
  )