Jump to content

Lisp lệnh KH trong chủ đề “'Tạo khung bản đồ'”

oh, hôm nay mới thấy lai cai upload lại, nên up nhờ các bác giúp em như hình vẽ dưới đây với!

(defun c:kh ();;; (princ "\n                      CHUONG TRINH VE KHUNG BAN DO .")(command "osnap" "Endpoint,Intersection")(setvar "blipmode" 1)   (setq sp (getpoint "\n Chon goc khung thu 1 (Goc trai ben tren): "))   (setq ep (getpoint sp "\n Chon goc khung thu 2 (Goc phai ben duoi): "));   (princ "\n Chon goc khung thu 1 (Goc trai ben tren): ");   (setq sp (getpoint)) ;  (prompt "\n Chon goc khung thu 2 (Goc phai ben duoi): ") ;  (setq ep (getcorner (getpoint)) )  (command "osnap" "off")   (setq tyle (getint "\n Hay cho ty le ban do <500>: "))   (if (= tyle nil) (setq tyle 500.0))(setvar "blipmode" 0);;--- Dat bien chung cho chuong trinh -----  (setq x1 (nth 0 sp)) (setq y1 (nth 1 sp))  (setq x2 (nth 0 ep)) (setq y2 (nth 1 ep))  (setq dayn (/ (* tyle 0.05) 500.0))  (setq kctn (/ tyle 142.857))  (setq ktmk (/ (* tyle 1.75) 500.0))  (setq caoc (/ (* tyle 0.90) 500.0))  (setq dich (/ (* tyle 0.33) 500.0));;;---- ve khung trong ------   (command "LAYER" "M" "KHUNG" "")   (Command "PLINE"             (list x1 y1)             (list x2 y1)             (list x2 y2)             (list x1 y2)             "C"   );;;;-------Ve khung ngoai ----------   (command "LAYER" "M" "KHUNG" "")   (Command "PLINE"             (list (- x1 kctn) (+ y1 kctn)) "w" dayn dayn             (list (+ x2 kctn) (+ y1 kctn))             (list (+ x2 kctn) (- y2 kctn))             (list (- x1 kctn) (- y2 kctn))             "C"   );;;------- Ve net ngang va doc ------- (setq nhay (/ tyle 10.0)) (setq tmpX1 (/ x1 nhay)) (setq tmpX2 (fix tmpX1)) (setq x (* tmpX2 nhay)) (setq tmpY1 (/ y2 nhay)) (setq tmpY2 (fix tmpY1)) (setq y (* tmpY2 nhay));-------------------------------------(command "style" "STANDARD" "" caoc "" "" "" "" "" "")(while (<= x x2)       (if (>= x x1)          (command "LINE" (list x y1) (list x (+ y1 kctn)) ""                   "LINE" (list x y2) (list x (- y2 kctn)) ""                   "TEXT" "C" (list x (+ y1 (/ kctn 2))) 0. (rtos x 2 0)                   "TEXT" "TC" (list x (- y2 (/ kctn 2))) 0. (rtos x 2 0)          )       ) ;endif  (setq x (+ x nhay)))(while (<= y y1)   (setq tmp1 (rtos y 2 0))   (setq len1 (strlen tmp1))   (if ( <= len1 3)      (progn (setq bef "000") (setq aff tmp1))      (progn (setq bef (substr tmp1 1 (- len1 3)))       (setq aff (substr tmp1 (- len1 2) 3))      )   ) ;;if      (if (>= y y2)           (command "LINE" (list x1 y) (list (- x1 kctn) y) ""                    "LINE" (list x2 y) (list (+ x2 kctn) y) ""                    "TEXT" "BC" (list (- x1 (/ kctn 2)) y) 0. bef                    "TEXT" "TC" (list (- x1 (/ kctn 2)) (- y dich)) 0. aff                    "TEXT" "BC" (list (+ x2 (/ kctn 2)) y) 0. bef                    "TEXT" "TC" (list (+ x2 (/ kctn 2)) (- y dich)) 0. aff           )      ); endif  (setq y (+ y nhay)));--------- Ve chu thap --------------(setq nhay (/ tyle 10.0)) (setq tmpX1 (/ x1 nhay)) (setq tmpX2 (fix tmpX1))(setq x (* tmpX2 nhay))(setq tmpY1 (/ y2 nhay)) (setq tmpY2 (fix tmpY1))(while (< x x2)  (setq y (* tmpY2 nhay))     (while (< y y1)        (if (and (>= x x1) (>= y y2))           (command "LINE" (list (- x ktmk) y) (list (+ x ktmk) y) "")        )        (if (and (>= y y2) (>= x x1))           (command "LINE" (list x (- y ktmk)) (list x (+ y ktmk)) "")        )       (setq y (+ y nhay))     )  (setq x (+ x nhay)))(command "REDRAW")); End of program 

 

và cả muốn vẽ tỷ lệ 500 gõ số 5, tỷ lệ 1000 gõ số 1 và 2000 gõ số 2 và lưu lại giá trị cho những lần sau.

https://www.cadviet.com/upfiles/3/104547_drawing.rar

104547_untitled_2.jpg104547_untitled2.jpg

Tệp .lsp gốc không còn trên máy chủ. Hãy chép mã nguồn bên dưới (lấy từ bài viết gốc) vào một tệp văn bản, lưu với đuôi .lsp.

Cách dùng

  1. Chép mã nguồn, lưu thành tệp 290633_kh.lsp.
  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 KH để chạy lisp.

Mã nguồn 290633_kh.lsp (trích từ bài viết gốc)

(defun c:kh ();;; (princ "\n                      CHUONG TRINH VE KHUNG BAN DO .")(command "osnap" "Endpoint,Intersection")(setvar "blipmode" 1)   (setq sp (getpoint "\n Chon goc khung thu 1 (Goc trai ben tren): "))   (setq ep (getpoint sp "\n Chon goc khung thu 2 (Goc phai ben duoi): "));   (princ "\n Chon goc khung thu 1 (Goc trai ben tren): ");   (setq sp (getpoint)) ;  (prompt "\n Chon goc khung thu 2 (Goc phai ben duoi): ") ;  (setq ep (getcorner (getpoint)) )  (command "osnap" "off")   (setq tyle (getint "\n Hay cho ty le ban do <500>: "))   (if (= tyle nil) (setq tyle 500.0))(setvar "blipmode" 0);;--- Dat bien chung cho chuong trinh -----  (setq x1 (nth 0 sp)) (setq y1 (nth 1 sp))  (setq x2 (nth 0 ep)) (setq y2 (nth 1 ep))  (setq dayn (/ (* tyle 0.05) 500.0))  (setq kctn (/ tyle 142.857))  (setq ktmk (/ (* tyle 1.75) 500.0))  (setq caoc (/ (* tyle 0.90) 500.0))  (setq dich (/ (* tyle 0.33) 500.0));;;---- ve khung trong ------   (command "LAYER" "M" "KHUNG" "")   (Command "PLINE"             (list x1 y1)             (list x2 y1)             (list x2 y2)             (list x1 y2)             "C"   );;;;-------Ve khung ngoai ----------   (command "LAYER" "M" "KHUNG" "")   (Command "PLINE"             (list (- x1 kctn) (+ y1 kctn)) "w" dayn dayn             (list (+ x2 kctn) (+ y1 kctn))             (list (+ x2 kctn) (- y2 kctn))             (list (- x1 kctn) (- y2 kctn))             "C"   );;;------- Ve net ngang va doc ------- (setq nhay (/ tyle 10.0)) (setq tmpX1 (/ x1 nhay)) (setq tmpX2 (fix tmpX1)) (setq x (* tmpX2 nhay)) (setq tmpY1 (/ y2 nhay)) (setq tmpY2 (fix tmpY1)) (setq y (* tmpY2 nhay));-------------------------------------(command "style" "STANDARD" "" caoc "" "" "" "" "" "")(while (<= x x2)       (if (>= x x1)          (command "LINE" (list x y1) (list x (+ y1 kctn)) ""                   "LINE" (list x y2) (list x (- y2 kctn)) ""                   "TEXT" "C" (list x (+ y1 (/ kctn 2))) 0. (rtos x 2 0)                   "TEXT" "TC" (list x (- y2 (/ kctn 2))) 0. (rtos x 2 0)          )       ) ;endif  (setq x (+ x nhay)))(while (<= y y1)   (setq tmp1 (rtos y 2 0))   (setq len1 (strlen tmp1))   (if ( <= len1 3)      (progn (setq bef "000") (setq aff tmp1))      (progn (setq bef (substr tmp1 1 (- len1 3)))       (setq aff (substr tmp1 (- len1 2) 3))      )   ) ;;if      (if (>= y y2)           (command "LINE" (list x1 y) (list (- x1 kctn) y) ""                    "LINE" (list x2 y) (list (+ x2 kctn) y) ""                    "TEXT" "BC" (list (- x1 (/ kctn 2)) y) 0. bef                    "TEXT" "TC" (list (- x1 (/ kctn 2)) (- y dich)) 0. aff                    "TEXT" "BC" (list (+ x2 (/ kctn 2)) y) 0. bef                    "TEXT" "TC" (list (+ x2 (/ kctn 2)) (- y dich)) 0. aff           )      ); endif  (setq y (+ y nhay)));--------- Ve chu thap --------------(setq nhay (/ tyle 10.0)) (setq tmpX1 (/ x1 nhay)) (setq tmpX2 (fix tmpX1))(setq x (* tmpX2 nhay))(setq tmpY1 (/ y2 nhay)) (setq tmpY2 (fix tmpY1))(while (< x x2)  (setq y (* tmpY2 nhay))     (while (< y y1)        (if (and (>= x x1) (>= y y2))           (command "LINE" (list (- x ktmk) y) (list (+ x ktmk) y) "")        )        (if (and (>= y y2) (>= x x1))           (command "LINE" (list x (- y ktmk)) (list x (+ y ktmk)) "")        )       (setq y (+ y nhay))     )  (setq x (+ x nhay)))(command "REDRAW")); End of program 

Thảo luận gốc

Lisp được chia sẻ trong chủ đề 'Tạo khung bản đồ'. Xem đúng bài viết #290633 để đọc hướng dẫn và trao đổi thêm.

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