AutoLISP®: Sample Programs


Programming in AutoCAD®

AutoLISP® and AutoCAD® are the trademarks of Autodesk® company.

Please find below the sample AutoLisp programs prepared by Guven Yasar Elyan. Feel free to copy and try them yourself to learn and improve your programming skills.

Farm House Project - FH-main.lsp

; GYE - FARM HOUSE
; FH-main.lsp
; The land area la:100x100 m2

;Functions
;initials

;get data
(defun data_fh ()
   ;x direction 100 m, y direction 100 m
  
   (setq x 100000
         y 100000
         d 100000 ;distance 100 m
   )
   (setq p1 (list 0 0 0)
         p2 (list x 0 0)
         p3 (list x y 0)
         p4 (list 0 y 0)
   )     
   (setq tp (list (+ x 2000) 0 0) )
   (setq sp tp
         h (/ d 100)
         rot 0
         txt "Güven Elyan"
   )

) ; end of defun data_fh 


;draw fence
(defun fence_draw ()
    ; define layer and draw fence
    ;red=1, yellow=2, green=3
    ;very nice red: 240, use for building

    (command "layer" "make" "fence" "Color" 42 "" "")  

    ;draw square
    (command "pline" p1 p2 p3 p4 p1 "")
 

) ; end of defun fence_draw

;zoom fh fence
(defun zoom_fh_fence ()
   ;zoom it to extends
   (command "zoom" "e") (command "zoom" "v")

)

 ;General
(command "ucsicon" "off")
;get data
(data_fh)
;draw fence
(fence_draw)
;zoom to see
(zoom_fh_fence)

 ; write text     
;(command "text" sp h rot txt)


;set layer to "0"
(command "layer" "set" 0 "")    

;make nil
(setq x nil y nil p1 nil p2 nil p3 nil p4 nil
      d nil sp nil h nil rot nil
)

back to home page