Lisp lệnh MTLL trong chủ đề “[Yêu cầu] Lisp tạo viewport từ khung chọn bên model.”
nhoc chỉ biết thêm màu mè thui ^^, set layer cho khung view đó, khóa khung view sau khi tạo, thay đổi cách nhập tỉ lệ cho đở phải tính tóan nếu tỉ lệ lẻ ^^, như anh KangKung viết thì ví dụ tỉ lệ 1/500 thì chạy lsp sẽ hỏi khi đó bạn nhập là 0.5 tương đương 1/500 hay 0.1 = 1/100, nhoc sửa xíu bạn cứ nhập đúng tỉ lệ mún thể hiện nhập vào thẳng 200, 100 , 75 , 20 v...v. Bạn thử xem ^^
;========LISP TAO VIEWPORT TREN LAYOUT BANG CACH CHON O MODEL======== ;=========================REV4ii===================================== (defun C:mtll( / os lst khung X_min Y_min X_max Y_max X index taphop tyle) (command "-layer" "m" "khung" "c" 3 "khung" "") (command "UNDO" "BE") (setq os(getvar "OSMODE")) (setvar "OSMODE" 0) (setq taphop(ssget )) (setq Tyle (getreal (strcat "\n Ty le 1/ <1000>: "))) (if (= Tyle nil) (setq Tyle 1000)) (setq soluong (sslength taphop)) (setq index 0) (command "LAYOUT" "N" "Layout1") (command "LAYOUT" "S" "Layout1") (command "ERASE" "ALL" "") (command "MODEL") (setq X 0) (command "ZOOM" "E") (while (< index soluong) (setq khung(ssname taphop index)) (setq lst(acet-geom-vertex-list khung)) (setq X_min 1000000000 Y_min 1000000000 X_max -1000000000 Y_max -1000000000) (foreach a lst (if (< (car a) X_min) (setq X_min (car a))) (if (< (cadr a) Y_min) (setq Y_min (cadr a))) (if (> (car a) X_max) (setq X_max (car a))) (if (> (cadr a) Y_max) (setq Y_max (cadr a))) ) (command "LAYOUT" "S" "Layout1") (command "ZOOM" "W" (list X_min Y_min) (list X_max Y_max)) (command "PLINE") (foreach a lst (command a)) (command "C") (command "MOVE" (entlast) "" (list X_min Y_min) (list X 0)) (command "ZOOM" "W" (list 0 0) (list (+ X 100) 0)) (command "SCALE" (entlast) "" (list X 0) (/ 1000 tyle)) (command "MVIEW" "O" (entlast)) (command "MSPACE") (command "ZOOM" (list X_min Y_min) (list X_max Y_max)) (command "PSPACE") (command "MVIEW" "L" "on" (entlast) "") (setq X(+ X 50 (/ (- X_max X_min) (/ tyle 1000)))) (command "ZOOM" "W" (list 0 0) (list (+ X 100) 0)) (setq index (+ index 1)) ) (command "MODEL") (command "UNDO" "END") (setvar "OSMODE" os) (princ) )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
- Chép mã nguồn, lưu thành tệp 227153_mtll.lsp.
- 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ẽ.
- Gõ lệnh MTLL để chạy lisp.
Mã nguồn 227153_mtll.lsp (trích từ bài viết gốc)
;========LISP TAO VIEWPORT TREN LAYOUT BANG CACH CHON O MODEL========;=========================REV4ii=====================================(defun C:mtll( / os lst khung X_min Y_min X_max Y_max X index taphop tyle)(command "-layer" "m" "khung" "c" 3 "khung" "") (command "UNDO" "BE") (setq os(getvar "OSMODE")) (setvar "OSMODE" 0) (setq taphop(ssget )) (setq Tyle (getreal (strcat "\n Ty le 1/ <1000>: "))) (if (= Tyle nil) (setq Tyle 1000)) (setq soluong (sslength taphop)) (setq index 0) (command "LAYOUT" "N" "Layout1") (command "LAYOUT" "S" "Layout1") (command "ERASE" "ALL" "") (command "MODEL") (setq X 0) (command "ZOOM" "E") (while (< index soluong) (setq khung(ssname taphop index)) (setq lst(acet-geom-vertex-list khung)) (setq X_min 1000000000 Y_min 1000000000 X_max -1000000000 Y_max -1000000000) (foreach a lst (if (< (car a) X_min) (setq X_min (car a))) (if (< (cadr a) Y_min) (setq Y_min (cadr a))) (if (> (car a) X_max) (setq X_max (car a))) (if (> (cadr a) Y_max) (setq Y_max (cadr a))) ) (command "LAYOUT" "S" "Layout1") (command "ZOOM" "W" (list X_min Y_min) (list X_max Y_max)) (command "PLINE") (foreach a lst (command a)) (command "C") (command "MOVE" (entlast) "" (list X_min Y_min) (list X 0)) (command "ZOOM" "W" (list 0 0) (list (+ X 100) 0)) (command "SCALE" (entlast) "" (list X 0) (/ 1000 tyle)) (command "MVIEW" "O" (entlast)) (command "MSPACE") (command "ZOOM" (list X_min Y_min) (list X_max Y_max)) (command "PSPACE") (command "MVIEW" "L" "on" (entlast) "") (setq X(+ X 50 (/ (- X_max X_min) (/ tyle 1000)))) (command "ZOOM" "W" (list 0 0) (list (+ X 100) 0)) (setq index (+ index 1)) ) (command "MODEL") (command "UNDO" "END") (setvar "OSMODE" os) (princ) )Thảo luận gốc
Lisp được chia sẻ trong chủ đề [Yêu cầu] Lisp tạo viewport từ khung chọn bên model.. Xem đúng bài viết #227153 để đọc hướng dẫn và trao đổi thêm.