Lisp lệnh MTL trong chủ đề “[Yêu cầu] Lisp tạo viewport từ khung chọn bên model.”
Bạn KangKung ơi cách bạn thêm vào hay hơn nhoc
, nhưng nhoc xài thử thì thấy nó ko đc như lsp thứ 1 của bạn, tạo xong thì mỗi layout nó lại tạo khung view chung cho khung 2 và 3, mình làm thử trên file vd của bạn tùng, và nó hơi dư layout 1, 2 ,3. Nên nhoc có sữa tí trong lsp bạn Tùng xem cái nào hợp thì xài hen ^^
;; free lisp from cadviet.com
;;; this lisp was downloaded from https://www.cadviet.com/forum/index.php?showtopic=68723&pid=226065&st=0&#entry226065
;; free lisp from cadviet.com
;;; this lisp was downloaded from https://www.cadviet.com/forum/index.php?showtopic=68723&pid=226065&st=0&#entry226065
;========LISP TAO VIEWPORT TREN LAYOUT BANG CACH CHON O MODEL========
(defun C:mtl(/ taphop soluong ten size i index oldos Tyle)
(command "UNDO" "BE")
(setq oldos (getvar "osmode"))
(setvar "OSMODE" 0)
(setq taphop(ssget))
(setq soluong (sslength taphop))
(setq size(getstring "\n Kho giay in A0/A1/A2/A3/A4? < A3 >: "))
(if (= size nil) (setq size A3))
(setq ten (getstring 1 "\n Nhap ten layout:"))
(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 index 0)
(setq i 0)
(while (< index soluong)
(setq i(1+ i))
(setq khung(ssname taphop index))
(setq lst(acet-geom-vertex-list khung))
(command "COPYCLIP" khung "")
(command "layout" "n" (strcat "layout" (rtos i 2 0)))
(command "LAYOUT" "N" (strcat ten (rtos i 2 0)))
(command "LAYOUT" "S" (strcat ten (rtos i 2 0)))
(command "layout" "d" "layout1" "")
(command "layout" "d" "layout2" "")
(command "layout" "d" "layout3" "")
(command "ERASE" "ALL" "")
(command "PASTECLIP" "0,0")
(command "SCALE" (entlast) "" "0,0" (/ 1000 tyle))
(command "MVIEW" "O" (entlast))
(command "MSPACE")
(command "ZOOM" (nth 0 lst) (nth 2 lst))
(command "PSPACE")
(command "ZOOM" "E")
(command "PLOT" "Y" "" "" size "M" "L" "N" "W" "0,0" (list (abs(- (car (nth 2 lst)) (car (nth 0 lst)))) (abs(- (cadr (nth 2 lst)) (cadr (nth 0 lst))))) "F" "" "Y" "" "Y" "N" "N" "N" "N" "Y" "N")
(command "MODEL")
(setq index (+ index 1))
)
(command "UNDO" "END")
(setvar "OSMODE" oldos)
(princ)
)
PS: vụ tỉ lệ nhoc có sữa lại tí, vd bạn nhập 1/500 >>> khung view sẽ scale lên 2 lần, tương tự cho các tỉ lệ khác bạn nhập ^^
;; free lisp from cadviet.com
;;; this lisp was downloaded from https://www.cadviet.com/forum/index.php?showtopic=68723&pid=226065&st=0&#entry226065
;; free lisp from cadviet.com
;;; this lisp was downloaded from https://www.cadviet.com/forum/index.php?showtopic=68723&pid=226065&st=0&#entry226065
;========LISP TAO VIEWPORT TREN LAYOUT BANG CACH CHON O MODEL========
(defun C:mtl(/ taphop soluong ten size i index oldos Tyle)
(command "UNDO" "BE")
(setq oldos (getvar "osmode"))
(setvar "OSMODE" 0)
(setq taphop(ssget))
(setq soluong (sslength taphop))
(setq size(getstring "\n Kho giay in A0/A1/A2/A3/A4? < A3 >: "))
(if (= size nil) (setq size A3))
(setq ten (getstring 1 "\n Nhap ten layout:"))
(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 index 0)
(setq i 0)
(while (< index soluong)
(setq i(1+ i))
(setq khung(ssname taphop index))
(setq lst(acet-geom-vertex-list khung))
(command "COPYCLIP" khung "")
(command "layout" "n" (strcat "layout" (rtos i 2 0)))
(command "LAYOUT" "N" (strcat ten (rtos i 2 0)))
(command "LAYOUT" "S" (strcat ten (rtos i 2 0)))
(command "layout" "d" "layout1" "")
(command "layout" "d" "layout2" "")
(command "layout" "d" "layout3" "")
(command "ERASE" "ALL" "")
(command "PASTECLIP" "0,0")
(command "SCALE" (entlast) "" "0,0" (/ 1000 tyle))
(command "MVIEW" "O" (entlast))
(command "MSPACE")
(command "ZOOM" (nth 0 lst) (nth 2 lst))
(command "PSPACE")
(command "ZOOM" "E")
(command "PLOT" "Y" "" "" size "M" "L" "N" "W" "0,0" (list (abs(- (car (nth 2 lst)) (car (nth 0 lst)))) (abs(- (cadr (nth 2 lst)) (cadr (nth 0 lst))))) "F" "" "Y" "" "Y" "N" "N" "N" "N" "Y" "N")
(command "MODEL")
(setq index (+ index 1))
)
(command "UNDO" "END")
(setvar "OSMODE" oldos)
(princ)
)
PS: vụ tỉ lệ nhoc có sữa lại tí, vd bạn nhập 1/500 >>> khung view sẽ scale lên 2 lần, tương tự cho các tỉ lệ khác bạn nhập ^^
- Tải lisp
- 226077_mtl.lsp
Cách dùng
- Tải tệp 226077_mtl.lsp về máy.
- 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 MTL để chạy lisp.
Mã nguồn 226077_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/
;; free lisp from cadviet.com
;;; this lisp was downloaded from https://www.cadviet.com/forum/index.php?showtopic=68723&pid=226065&st=0entry226065
;; free lisp from cadviet.com
;;; this lisp was downloaded from https://www.cadviet.com/forum/index.php?showtopic=68723&pid=226065&st=0entry226065
;========LISP TAO VIEWPORT TREN LAYOUT BANG CACH CHON O MODEL========
(defun C:mtl(/ taphop soluong ten size i index oldos Tyle)
(command "UNDO" "BE")
(setq oldos (getvar "osmode"))
(setvar "OSMODE" 0)
(setq taphop(ssget))
(setq soluong (sslength taphop))
(setq size(getstring "\n Kho giay in A0/A1/A2/A3/A4? < A3 >: "))
(if (= size nil) (setq size A3))
(setq ten (getstring 1 "\n Nhap ten layout:"))
(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 index 0)
(setq i 0)
(while (< index soluong)
(setq i(1+ i))
(setq khung(ssname taphop index))
(setq lst(acet-geom-vertex-list khung))
(command "COPYCLIP" khung "")
(command "layout" "n" (strcat "layout" (rtos i 2 0)))
(command "LAYOUT" "N" (strcat ten (rtos i 2 0)))
(command "LAYOUT" "S" (strcat ten (rtos i 2 0)))
(command "layout" "d" "layout1" "")
(command "layout" "d" "layout2" "")
(command "layout" "d" "layout3" "")
(command "ERASE" "ALL" "")
(command "PASTECLIP" "0,0")
(command "SCALE" (entlast) "" "0,0" (/ 1000 tyle))
(command "MVIEW" "O" (entlast))
(command "MSPACE")
(command "ZOOM" (nth 0 lst) (nth 2 lst))
(command "PSPACE")
(command "ZOOM" "E")
(command "PLOT" "Y" "" "" size "M" "L" "N" "W" "0,0" (list (abs(- (car (nth 2 lst)) (car (nth 0 lst)))) (abs(- (cadr (nth 2 lst)) (cadr (nth 0 lst))))) "F" "" "Y" "" "Y" "N" "N" "N" "N" "Y" "N")
(command "MODEL")
(setq index (+ index 1))
)
(command "UNDO" "END")
(setvar "OSMODE" oldos)
(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 #226077 để đọc hướng dẫn và trao đổi thêm.