Jump to content

Lisp lệnh K trong chủ đề “các bác cho em xin lisp khổ giấy với ạ”

Lâu rồi không biết tay nghề có bị cùn ko nữa, bạn nguyentan1991 thử xem nhé!

(defun c:k (/ oldlst a b c d e f g h kho TL)
(command "undo" "be")
(setq oldlst (mapcar 'getvar (list "CMDECHO" "OSMODE" "cecolor")))
(setvar "CMDECHO" 0)
    (setq a (getpoint "\n chon diem chen :"))
(if (not TL) (setq TL 1.00))
 (setq TL1 (getDIST (strcat "\nScale <" (rtos TL 2 2) ">:")))
(if TL1 (setq TL TL1))
(setvar "osmode" 0)
(if (not (tblsearch "layer" "Defpoints")) (Command "layer" "N" "Defpoints" ""))
(initget "0 1 2 3 4")
       (setq kho (getkword "\Kho A0 _ Kho A1 _ Kho A2 _ Kho A3 _ Kho A4 ? <0>:"))
 (if (= kho "0")
     (progn
             (setq b (polar a 0 (* TL 1189)))
                     (setq c (polar b (/ pi 2) (* TL 841)))
                     (setq d (polar a (/ pi 2) (* TL 841)))
             (setq e (polar a (/ pi 4) (* TL (sqrt (* 2 12 12)))))
                     (setq f (polar e 0 (- (* TL 1189) (* TL 24))))
                     (setq g (polar f (/ pi 2) (- (* TL 841) (* TL 24))))
                     (setq h (polar e (/ pi 2) (- (* TL 841) (* TL 24))))
  (command "Pline" e f g h "c")            
(command "change" "last" "" "properties" "layer" "0" "")
(setvar "cecolor" "4")
  (command "Pline" a b c d "c")
(command "change" "last" "" "properties" "layer" "defpoints" "")))    
 (if (= kho "1")
     (progn
             (setq b (polar a 0 (* TL 841)))
                     (setq c (polar b (/ pi 2) (* TL 594)))
                     (setq d (polar a (/ pi 2) (* TL 594)))
            (setq e (polar a (/ pi 4) (* TL (sqrt (* 2 12 12)))))
                     (setq f (polar e 0 (- (* TL 841) (* TL 24))))
                     (setq g (polar f (/ pi 2) (- (* TL 594) (* TL 24))))
                     (setq h (polar e (/ pi 2) (- (* TL 594) (* TL 24))))
  (command "Pline" e f g h "c")            
(command "change" "last" "" "properties" "layer" "0" "")
(setvar "cecolor" "4")
  (command "Pline" a b c d "c")
(command "change" "last" "" "properties" "layer" "defpoints" "")))
 (if (= kho "2")
     (progn
             (setq b (polar a 0 (* TL 594)))
                     (setq c (polar b (/ pi 2) (* TL 420)))
                     (setq d (polar a (/ pi 2) (* TL 420)))
             (setq e (polar a (/ pi 4) (* TL (sqrt (* 2 100)))))
                     (setq f (polar e 0 (- (* TL 594) (* TL 20))))
                     (setq g (polar f (/ pi 2) (- (* TL 420) (* TL 20))))
                     (setq h (polar e (/ pi 2) (- (* TL 420) (* TL 20))))
  (command "Pline" e f g h "c")            
(command "change" "last" "" "properties" "layer" "0" "")
(setvar "cecolor" "4")
  (command "Pline" a b c d "c")
(command "change" "last" "" "properties" "layer" "defpoints" "")))
 (if (= kho "3")
     (progn
             (setq b (polar a 0 (* tl 420)))
                     (setq c (polar b (/ pi 2) (* TL 297)))
                     (setq d (polar a (/ pi 2) (* TL 297)))
             (setq e (polar a (/ pi 4) (* TL (sqrt (* 2 100)))))
                     (setq f (polar e 0 (- (* TL 420) (* TL 20))))
                     (setq g (polar f (/ pi 2) (- (* TL 297) (* TL 20))))
                     (setq h (polar e (/ pi 2) (- (* TL 297) (* TL 20))))
(command "Pline" e f g h "c")
  (command "change" "last" "" "properties" "layer" "0" "")
(setvar "cecolor" "4")
(command "Pline" a b c d "c")
  (command "change" "last" "" "properties" "layer" "defpoints" "")))
 (if (= kho "4")
     (progn
             (setq b (polar a 0 (* TL 297)))
              (setq c (polar b (/ pi 2) (* TL 210)))
                     (setq d (polar a (/ pi 2) (* TL 210)))
            (setq e (polar a (/ pi 4) (* TL (sqrt (* 2 81)))))
                     (setq f (polar e 0 (- (* TL 297) (* TL 18))))
                     (setq g (polar f (/ pi 2) (- (* TL 210) (* TL 18))))
                     (setq h (polar e (/ pi 2) (- (* TL 210) (* TL 18))))
  (command "Pline" e f g h "c")            
(command "change" "last" "" "properties" "layer" "0" "")
(setvar "cecolor" "4")
  (command "Pline" a b c d "c")
(command "change" "last" "" "properties" "layer" "defpoints" "")))
(mapcar 'setvar (list "CMDECHO" "OSMODE" "cecolor") oldlst)
(command "undo" "e")
(princ))

Cách dùng

  1. Tải tệp 302200_k.lsp về máy.
  2. Trong AutoCAD gõ lệnh APPLOAD, chọn tệp vừa tải rồi bấm Load. Cũng có thể kéo thả tệp .lsp vào cửa sổ bản vẽ.
  3. Gõ lệnh K để chạy lisp.

Mã nguồn 302200_k.lsp

;; free lisp from cadviet.com
;;; this lisp was downloaded from https://www.cadviet.com/forum/topic/106079-c%C3%A1c-b%C3%A1c-cho-em-xin-lisp-kh%E1%BB%95-gi%E1%BA%A5y-v%E1%BB%9Bi-%E1%BA%A1/
(defun c:k (/ oldlst a b c d e f g h kho TL)
(command "undo" "be")
(setq oldlst (mapcar 'getvar (list "CMDECHO" "OSMODE" "cecolor")))
(setvar "CMDECHO" 0)
    (setq a (getpoint "\n chon diem chen :"))
(if (not TL) (setq TL 1.00))
 (setq TL1 (getDIST (strcat "\nScale <" (rtos TL 2 2) ">:")))
(if TL1 (setq TL TL1))
(setvar "osmode" 0)
(if (not (tblsearch "layer" "Defpoints")) (Command "layer" "N" "Defpoints" ""))
(initget "0 1 2 3 4")
       (setq kho (getkword "\Kho A0 _ Kho A1 _ Kho A2 _ Kho A3 _ Kho A4 [0/1/2/3/4]? <0>:"))
 (if (= kho "0")
     (progn
             (setq b (polar a 0 (* TL 1189)))
                     (setq c (polar b (/ pi 2) (* TL 841)))
                     (setq d (polar a (/ pi 2) (* TL 841)))
             (setq e (polar a (/ pi 4) (* TL (sqrt (* 2 12 12)))))
                     (setq f (polar e 0 (- (* TL 1189) (* TL 24))))
                     (setq g (polar f (/ pi 2) (- (* TL 841) (* TL 24))))
                     (setq h (polar e (/ pi 2) (- (* TL 841) (* TL 24))))
  (command "Pline" e f g h "c")            
(command "change" "last" "" "properties" "layer" "0" "")
(setvar "cecolor" "4")
  (command "Pline" a b c d "c")
(command "change" "last" "" "properties" "layer" "defpoints" "")))    
 (if (= kho "1")
     (progn
             (setq b (polar a 0 (* TL 841)))
                     (setq c (polar b (/ pi 2) (* TL 594)))
                     (setq d (polar a (/ pi 2) (* TL 594)))
            (setq e (polar a (/ pi 4) (* TL (sqrt (* 2 12 12)))))
                     (setq f (polar e 0 (- (* TL 841) (* TL 24))))
                     (setq g (polar f (/ pi 2) (- (* TL 594) (* TL 24))))
                     (setq h (polar e (/ pi 2) (- (* TL 594) (* TL 24))))
  (command "Pline" e f g h "c")            
(command "change" "last" "" "properties" "layer" "0" "")
(setvar "cecolor" "4")
  (command "Pline" a b c d "c")
(command "change" "last" "" "properties" "layer" "defpoints" "")))
 (if (= kho "2")
     (progn
             (setq b (polar a 0 (* TL 594)))
                     (setq c (polar b (/ pi 2) (* TL 420)))
                     (setq d (polar a (/ pi 2) (* TL 420)))
             (setq e (polar a (/ pi 4) (* TL (sqrt (* 2 100)))))
                     (setq f (polar e 0 (- (* TL 594) (* TL 20))))
                     (setq g (polar f (/ pi 2) (- (* TL 420) (* TL 20))))
                     (setq h (polar e (/ pi 2) (- (* TL 420) (* TL 20))))
  (command "Pline" e f g h "c")            
(command "change" "last" "" "properties" "layer" "0" "")
(setvar "cecolor" "4")
  (command "Pline" a b c d "c")
(command "change" "last" "" "properties" "layer" "defpoints" "")))
 (if (= kho "3")
     (progn
             (setq b (polar a 0 (* tl 420)))
                     (setq c (polar b (/ pi 2) (* TL 297)))
                     (setq d (polar a (/ pi 2) (* TL 297)))
             (setq e (polar a (/ pi 4) (* TL (sqrt (* 2 100)))))
                     (setq f (polar e 0 (- (* TL 420) (* TL 20))))
                     (setq g (polar f (/ pi 2) (- (* TL 297) (* TL 20))))
                     (setq h (polar e (/ pi 2) (- (* TL 297) (* TL 20))))
(command "Pline" e f g h "c")
  (command "change" "last" "" "properties" "layer" "0" "")
(setvar "cecolor" "4")
(command "Pline" a b c d "c")
  (command "change" "last" "" "properties" "layer" "defpoints" "")))
 (if (= kho "4")
     (progn
             (setq b (polar a 0 (* TL 297)))
              (setq c (polar b (/ pi 2) (* TL 210)))
                     (setq d (polar a (/ pi 2) (* TL 210)))
            (setq e (polar a (/ pi 4) (* TL (sqrt (* 2 81)))))
                     (setq f (polar e 0 (- (* TL 297) (* TL 18))))
                     (setq g (polar f (/ pi 2) (- (* TL 210) (* TL 18))))
                     (setq h (polar e (/ pi 2) (- (* TL 210) (* TL 18))))
  (command "Pline" e f g h "c")            
(command "change" "last" "" "properties" "layer" "0" "")
(setvar "cecolor" "4")
  (command "Pline" a b c d "c")
(command "change" "last" "" "properties" "layer" "defpoints" "")))
(mapcar 'setvar (list "CMDECHO" "OSMODE" "cecolor") oldlst)
(command "undo" "e")
(princ))

Thảo luận gốc

Lisp được chia sẻ trong chủ đề các bác cho em xin lisp khổ giấy với ạ. Xem đúng bài viết #302200 để đọc hướng dẫn và trao đổi thêm.

Về Thư viện AutoLisp (trang 164)