Author Topic: (code) Another getreal function  (Read 1499 times)

0 Members and 1 Guest are viewing this topic.

Mark

  • Custom Title
  • Seagull
  • Posts: 28683
(code) Another getreal function
« 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)
  )

TheSwamp.org  (serving the CAD community since 2003)