Jump to content

Lisp lệnh MTL trong chủ đề “[Yêu cầu] Lisp tạo viewport từ khung chọn bên model.”

Bạn khaosatheco thân mến.

Lisp #54 vẫn chạy được nếu polyline kín của bạn chỉ có 5 điểm hoặc có 4 điểm đầu tiên trùng với 4 góc của khung hình chữ nhật. Tuy nhiên tôi đã sửa lại theo ý của bạn là chọn polyline kín thì lisp vẫn chạy được. Thậm chí nếu polyline có hình loằng ngoằng thì lisp vẫn tạo cho bạn viewport bao kín hình polyline đó đúng với tỷ lệ bạn nhập vào.

https://www.cadviet.com/upfiles/3/71162_mtl_rev4i.lsp

;========LISP TAO VIEWPORT TREN LAYOUT BANG CACH CHON O MODEL======== ;===============REV4i===================== (defun C:mtl( / lst khung X_min Y_min X_max Y_max X index taphop) (command "UNDO" "BE") (setvar "OSMODE" 0) (setq taphop(ssget )) (if (= Tyle nil) (setq Tyle1 1) (setq Tyle1 Tyle)) (setq Tyle (getreal (strcat "\n Ty le: <" (rtos Tyle1 2 0) "> "))) (if (= Tyle nil) (setq Tyle Tyle1)) (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 "RECTANG" (list X_min Y_min) (list X_max Y_max)) (command "MOVE" (entlast) "" (list X_min Y_min) (list X 0)) (command "SCALE" (entlast) "" (list X 0) (/ 1 tyle)) (command "MVIEW" "O" (entlast)) (command "MSPACE") (command "ZOOM" (list X_min Y_min) (list X_max Y_max)) (command "PSPACE") (setq X(+ X 50 (/ (abs(- X_max X_min)) tyle))) (command "ZOOM" "W" (list 0 0) (list (+ X 100) 0)) (setq index (+ index 1)) ) (command "MODEL") (command "UNDO" "END") (setvar "OSMODE" 15359) (princ) )

Cách dùng

  1. Tải tệp 227047_mtl.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 MTL để chạy lisp.

Mã nguồn 227047_mtl.lsp

;; free lisp from cadviet.com
;;; this lisp was downloaded from https://www.cadviet.com/forum/topic/68723-y%C3%AAu-c%E1%BA%A7u-lisp-t%E1%BA%A1o-viewport-t%E1%BB%AB-khung-ch%E1%BB%8Dn-b%C3%AAn-model/?page=3
;========LISP TAO VIEWPORT TREN LAYOUT BANG CACH CHON O MODEL========;===============REV4i=====================(defun C:mtl( / lst khung X_min Y_min X_max Y_max X index taphop)  (command "UNDO" "BE")  (setvar "OSMODE" 0)  (setq taphop(ssget ))  (if (= Tyle nil)    (setq Tyle1 1)    (setq Tyle1 Tyle))  (setq Tyle (getreal (strcat "\n Ty le: <" (rtos Tyle1 2 0) "> ")))  (if (= Tyle nil)    (setq Tyle Tyle1))  (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 "RECTANG" (list X_min Y_min) (list X_max Y_max))    (command "MOVE" (entlast) "" (list X_min Y_min) (list X 0))    (command "SCALE" (entlast) "" (list X 0) (/ 1 tyle))    (command "MVIEW" "O" (entlast))    (command "MSPACE")    (command "ZOOM" (list X_min Y_min) (list X_max Y_max))    (command "PSPACE")    (setq X(+ X 50 (/ (abs(- X_max X_min)) tyle)))    (command "ZOOM" "W" (list 0 0) (list (+ X 100) 0))    (setq index (+ index 1))    )  (command "MODEL")  (command "UNDO" "END")  (setvar "OSMODE" 15359)  (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 #227047 để đọc hướng dẫn và trao đổi thêm.

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