Jump to content

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

sax lạ vậy bạn tải lại bản này xem ngắn gọn hơn xíu chắc ko lỗi ^^

;========LISP TAO VIEWPORT TREN LAYOUT BANG CACH CHON O MODEL========
;===============REV3=====================
(defun C:mtl(/ taphop soluong ten khung tyle oldos i lst X index)
(command "UNDO" "BE")
(setq oldos (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)
(setq i 0)
(setq ten (getstring "\n Nhap ten layout:"))
(command "layout" "N" ten)
(command "LAYOUT" "S" ten)
(command "ERASE" "ALL" "")
(command "MODEL")
(setq X 0)
(command "ZOOM" "E")
(while (< index soluong)
(setq i(1+ i))
(setq khung(ssname taphop index))
(setq lst(acet-geom-vertex-list khung))
(command "COPYCLIP" khung "")
(command "LAYOUT" "S" ten)
(command "PASTECLIP" (list X 0))
(command "SCALE" (entlast) "" (list X 0) (/ 1000 tyle))
(command "MVIEW" "O" (entlast))
(command "MSPACE")
(command "ZOOM" (nth 0 lst) (nth 2 lst))
(command "PSPACE")
(command "Mview" "L" "on" (entlast) "")
(setq X(+ X 50 (/ (abs(- (car (nth 2 lst)) (car (nth 0 lst)))) (/ tyle 1000))))
(command "ZOOM" "W" (list 0 0) (list (+ X 100) 0))
(setq index (+ index 1))
)
(command "MODEL")
(command "UNDO" "END")
(setvar "OSMODE" oldos)
(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

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

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

;========LISP TAO VIEWPORT TREN LAYOUT BANG CACH CHON O MODEL========
;===============REV3=====================
(defun C:mtl(/ taphop soluong ten khung tyle oldos i lst X index)
 (command "UNDO" "BE")
 (setq oldos (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)
 (setq i 0)
 (setq ten (getstring "\n Nhap ten layout:"))
 (command "layout" "N" ten)
 (command "LAYOUT" "S" ten)
 (command "ERASE" "ALL" "")
 (command "MODEL")
 (setq X 0)
 (command "ZOOM" "E")
 (while (< index soluong)
(setq i(1+ i))
(setq khung(ssname taphop index))
(setq lst(acet-geom-vertex-list khung))
(command "COPYCLIP" khung "")
(command "LAYOUT" "S" ten)
(command "PASTECLIP" (list X 0))
(command "SCALE" (entlast) "" (list X 0) (/ 1000 tyle))
(command "MVIEW" "O" (entlast))
(command "MSPACE")
(command "ZOOM" (nth 0 lst) (nth 2 lst))
(command "PSPACE")
(command "Mview" "L" "on" (entlast) "")
(setq X(+ X 50 (/ (abs(- (car (nth 2 lst)) (car (nth 0 lst)))) (/ tyle 1000))))
(command "ZOOM" "W" (list 0 0) (list (+ X 100) 0))
(setq index (+ index 1))
)
 (command "MODEL")
 (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 #226104 để đọc hướng dẫn và trao đổi thêm.

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