Autolisp Example Programs
Autolisp Example Programs
Example Program 1:
Description: To obtain age of the user and convert it into
days and weeks.
(defun C:myProg()
(setq intAge (getint "\n Enter your Age: "))
(setq intDays (* intAge 365))
(setq intWeeks (/ intDays 7))
(princ (strcat "\n You are " (itoa intDays) " Days old!"))
(princ (strcat "\n You are " (itoa intWeeks) " Weeks old!"))
(princ)
)
Execution:
Command: (load "myProg")<enter>
Command: myProg<enter>
Example Program 2:
(defun C:myprog1()
(setq pt1(getpoint "\n Pick First Point: "))
(setq pt2(getpoint "\n Pick Last Point: "))
(setq x1 (car pt1)) ;x-coord of point one
(setq x2 (car pt2)) ;x-coord of point two
(setq y1 (cadr pt1)) ;y-coord of point one
(setq y2 (cadr pt2)) ;y-coord of point two
(setq xdis (- x2 x1)) ;distance in x direction between points
(setq ydis (- y2 y1)) ;distance in y direction between points
(setq slpdis (sqrt (+ (expt xdis 2.0) (expt ydis 2.0)))) ;Asq+Bsq=C
sq
(princ (strcat "\n Distance = " (rtos slpdis 4 4)))
(princ)
)
Execution:
Command: (load myprog1)<enter>
Command: myprog1<enter>
command
Eg: (command "dist" pt1 pt2)(princ)