Lisp lệnh KVP trong chủ đề “Lisp tự động sắp xếp bản vẽ từ model sang khung in bên layout”
Mình thấy có cái này:
(defun C:KVP( / os lst khung X_min Y_min X_max Y_max X index taphop tyle)
(command "layer" "m" "khung" "p" "n" "khung" "")
(setvar "cmdecho" 0)
(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" "In")
(command "LAYOUT" "S" "In")
(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" "In")
(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ải lisp
- 249402_kvp.lsp
Cách dùng
- Tải tệp 249402_kvp.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 KVP để chạy lisp.
Mã nguồn 249402_kvp.lsp
;; free lisp from cadviet.com
;;; this lisp was downloaded from https://www.cadviet.com/forum/topic/18748-lisp-t%E1%BB%B1-%C4%91%E1%BB%99ng-s%E1%BA%AFp-x%E1%BA%BFp-b%E1%BA%A3n-v%E1%BA%BD-t%E1%BB%AB-model-sang-khung-in-b%C3%AAn-layout/
(defun C:KVP( / os lst khung X_min Y_min X_max Y_max X index taphop tyle)
(command "layer" "m" "khung" "p" "n" "khung" "")
(setvar "cmdecho" 0)
(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" "In")
(command "LAYOUT" "S" "In")
(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" "In")
(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ủ đề Lisp tự động sắp xếp bản vẽ từ model sang khung in bên layout. Xem đúng bài viết #249402 để đọc hướng dẫn và trao đổi thêm.