boundBox.lsp:
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;Drawing a bounding box with LISP. DraftSight LISP webinar No. 3 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;Error trap example:
(defun *error* (msg) ;;; *error* is a LISP built-in function ;;;(if (= msg "User break") ;;; (setq temperror *error*) ;;; This line is an alternative for error trapping ;;; (setq oSnapMode (getvar "osmode")) ;;; (Command "undo" "M") ;;; The Mark option of the UNDO tool allows inserting a marker in the undo file. (progn (princ "The following error occurred: ") (princ msg)
(setvar "osmode" oSnapMode) (terpri) ) ;;;) (setq *error* nil) ;;; (setq *error* temperror) ;;; is anothor option (princ) )
;;;;(defun C:bdbox ( / pt1 Lng pt4 pt3 pt2) (defun C:bdbox () ;;;;;;;;;/ pt1 Lng pt4 pt3 pt2) (setq pt1 (getpoint "\\nClick for the lower left corner: ")) (setq Lng (getdist "\\nEnter the length of the box: ")) (setq Pt4 (polar (setq pt3 (polar ;;;;;;;; The polar function computes a point via polar coordinates.
(setq pt2 (polar pt1 0 Lng) ;;;; Let's change Lng to Lnd is an intentional error ) (* 0.5 pi) Lng ) ) pi Lng ) ) (command "LINE" pt1 pt2 pt3 pt4 "C")
;;;;;;;;;;Alert function examples:
(princ "\\n") (alert "This shows an INFORMATION example1." "Example1" "INFORMATION") (alert "This shows an EXCLAMATION example2." "Example2" "EXCLAMATION") (alert "This shows a STOP example3." "Example3" "STOP") (setq ANS (alert "This shows a QUESTION example4." "Example4" "QUESTION")) (if (= ANS nil) (princ "Your answer was No"))
;;;;;;Debugging ;;Change the bdbox function local argument passing variables to global ;; Comment the line (defun C:bdbox ( / pt1 Lng pt4 pt3 pt2) ;; and uncomment (defun C:bdbox ()
(princ "\\npt1 :")(princ pt1)(princ) (princ "\\nLng :")(princ Lng)(princ)
(princ) )
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
abc.lsp
(defun C:abc() (prompt "\\nThis progran draws a line between two points to be input by the user...") (setq PT1 (getpoint "\\nEnter the starting point: ")) (setq PT2 (getpoint PT1 "\\nEnter the ending point: ")) (command "LINE" PT1 PT2 "") (prompt "\\nDone.\\n") (princ) )
Broadcasted on November 28, 2012
