Jump to content

Lisp tạo viewport từ khung chọn bên model.

Mạn phép bạn KangKung cho nhoc sữa lại tí :D, nhoc cũng mới tập tềnh học lsp, nên thấy lsp nào nhoc có khả năng thử chỉnh sữa nhằm rèn luyện ^^
-Yêu cầu bổ sung đầu tiên của bạn nhoc hỉu sao sữa vậy bạn xem thử hen
-yêu cầu thứ 2 chưa hỉu ko pit sữa sao ^^
-thắc mắc thứ 3 của bạn, vậy thể theo nguyện vọng bỏ lun phần đó cho nó đỡ rùm rà hen :D

;========LISP TAO VIEWPORT TREN LAYOUT BANG CACH CHON O MODEL========
(defun C:mtl(/ taphop soluong ten size i index oldos)
(command "UNDO" "BE")
(setq oldos (getvar "osmode"))
(setvar "OSMODE" 0)
(setq taphop(ssget))
(setq soluong (sslength taphop))
(setq ten (getstring 1 "\n Nhap ten layout:"))
(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 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 "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)
)

Cách dùng

  1. Tải tệp 226057_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 226057_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/
;========LISP TAO VIEWPORT TREN LAYOUT BANG CACH CHON O MODEL========
(defun C:mtl(/ taphop soluong ten size i index oldos)
 (command "UNDO" "BE")
 (setq oldos (getvar "osmode"))
 (setvar "OSMODE" 0)
 (setq taphop(ssget))
 (setq soluong (sslength taphop))
 (setq ten (getstring 1 "\n Nhap ten layout:"))
 (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 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 "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 #226057 để đọc hướng dẫn và trao đổi thêm.

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