Lisp tạo viewport từ khung chọn bên model.
Vào lúc 26/2/2013 tại 11:09, KangKung đã nói:
Lisp mới tạo viewport cho tất cả hình chữ nhật có cạnh nằm ngang, đứng, ... ngồi
hoặc nghiêng. Sơ qua về các đặc điểm của Lisp này:
1. Tạo viewport cho tất cả các khung hình chữ nhật
2. Thêm lựa chọn Xref khung tên bản vẽ
3. Các viewport được sắp xếp theo phương đứng thay vì phương ngang như các Lisp trước
Bác nào có nhu cầu thì down về rồi test thử và cho ý kiến nhé.
https://www.cadviet.com/upfiles/3/71162_mtl_rev5.lsp
P/S: Lisp này sẽ giảm rất nhiều thao tác và thời gian cho những ai biên tập bản đồ khu vực rộng đặc biệt là bản đồ dạng tuyến.
@Nhoclangbat: Sẽ post Lisp theo yêu cầu của nhoc sau nhé.
;========LISP TAO VIEWPORT TREN LAYOUT BANG CACH CHON O MODEL======== ;============================REV5==================================== ;=========THEM LUA CHON XOAY HCN NGHIENG VA XREF KHUNG TEN=========== (defun C:mtl( / os lst khung pt0 pt1 pt2 pt3 Y index taphop xrefFile xref) (command "UNDO" "BE") (setq os(getvar "OSMODE")) (setvar "OSMODE" 0) (setq taphop(ssget (LIST (CONS 0 "POLYLINE,LWPOLYLINE")))) (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 xref(getstring "\n Ban co muon chen file khung ten hay khong? <Y/N>:")) (if (= (strcase xref) "Y") (progn (if (not Path) (setq Path(getvar "dwgprefix"))) (setq xrefFile(getfiled "Chon File khung ten" Path "dwg" 2)) (setq Path xrefFile))) (setq soluong (sslength taphop)) (setq index 0) (command "LAYOUT" "N" "Layout1") (command "LAYOUT" "S" "Layout1") (command "ERASE" "ALL" "") (command "ZOOM" "E") (command "MODEL") (setq Y 0) (command "ZOOM" "E") (while (< index soluong) (setq khung(ssname taphop index)) (setq lst(acet-geom-vertex-list khung)) (setq lst (vl-sort lst '(lambda (e1 e2) (if (/= (car e1) (car e2)) (< (car e1) (car e2)) (< (cadr e1) (cadr e2)))))) (setq pt0(nth 0 lst) pt3(nth 3 lst)) (if (> (cadr (nth 1 lst)) (cadr (nth 2 lst))) (setq pt1(nth 1 lst) pt2(nth 2 lst)) (setq pt1(nth 2 lst) pt2(nth 1 lst)) ) (command "LAYOUT" "S" "Layout1") (if (> (distance pt2 pt0) (distance pt1 pt0)) (command "RECTANG" (list 0 Y) (list (distance pt2 pt0) (+ Y (distance pt1 pt0)))) (command "RECTANG" (list 0 Y) (list (distance pt1 pt0) (+ y (distance pt2 pt0)))) ) (command "SCALE" (entlast) "" (list 0 Y) (/ 1 tyle)) (command "MVIEW" "O" (entlast)) (if (= (strcase xref) "Y") (command "xref" "A" xrefFile (list 0 Y) "" "" "")) (command "MSPACE") (if (> (distance pt2 pt0) (distance pt1 pt0)) (command "DVIEW" khung "" "TW" (- 90 (* (/ (angle pt0 pt1) pi) 180)) "") (command "DVIEW" khung "" "TW" (- 0 (* (/ (angle pt0 pt1) pi) 180)) "") ) (command "ZOOM" "W" pt0 pt3) (command "PSPACE") (command "TEXT" "J" "MR" (list -50 (+ Y (/ (distance pt1 pt0) (* 2 tyle)))) (* 25 tyle) "0" (strcat "VP " (rtos (1+ index) 2 0)) "") (if (> (distance pt2 pt0) (distance pt1 pt0)) (setq Y(- Y 50 (/ (distance pt1 pt0) tyle))) (setq Y(- Y 50 (/ (distance pt2 pt0) tyle))) ) (command "ZOOM" "W" (list -100 (+ Y (distance pt3 pt0))) (list (distance pt3 pt0) (- Y 50 (distance pt3 pt0)))) (setq index (+ index 1)) ) (command "ZOOM" "E") (command "MODEL") (command "UNDO" "END") (setvar "OSMODE" os) (princ) )
@kangkang Cho mình hỏi là Lisp này không chay đc trên Cad2019 là do đâu? mong đc sự giải đáp. cảm ơn!
- Tải lisp
- 432964_mtl.lsp
Cách dùng
- Tải tệp 432964_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 432964_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=6
;========LISP TAO VIEWPORT TREN LAYOUT BANG CACH CHON O MODEL========
;============================REV5====================================
;=========THEM LUA CHON XOAY HCN NGHIENG VA XREF KHUNG TEN===========
(defun C:mtl( / os lst khung pt0 pt1 pt2 pt3 Y index taphop xrefFile xref)
(command "UNDO" "BE")
(setq os(getvar "OSMODE"))
(setvar "OSMODE" 0)
(setq taphop(ssget (LIST (CONS 0 "POLYLINE,LWPOLYLINE"))))
(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 xref(getstring "\n Ban co muon chen file khung ten hay khong? <Y/N>:"))
(if (= (strcase xref) "Y")
(progn
(if (not Path)
(setq Path(getvar "dwgprefix")))
(setq xrefFile(getfiled "Chon File khung ten" Path "dwg" 2))
(setq Path xrefFile)))
(setq soluong (sslength taphop))
(setq index 0)
(command "LAYOUT" "N" "Layout1")
(command "LAYOUT" "S" "Layout1")
(command "ERASE" "ALL" "")
(command "ZOOM" "E")
(command "MODEL")
(setq Y 0)
(command "ZOOM" "E")
(while (< index soluong)
(setq khung(ssname taphop index))
(setq lst(acet-geom-vertex-list khung))
(setq lst (vl-sort lst '(lambda (e1 e2) (if (/= (car e1) (car e2)) (< (car e1) (car e2)) (< (cadr e1) (cadr e2))))))
(setq pt0(nth 0 lst) pt3(nth 3 lst))
(if (> (cadr (nth 1 lst)) (cadr (nth 2 lst)))
(setq pt1(nth 1 lst) pt2(nth 2 lst))
(setq pt1(nth 2 lst) pt2(nth 1 lst))
)
(command "LAYOUT" "S" "Layout1")
(if (> (distance pt2 pt0) (distance pt1 pt0))
(command "RECTANG" (list 0 Y) (list (distance pt2 pt0) (+ Y (distance pt1 pt0))))
(command "RECTANG" (list 0 Y) (list (distance pt1 pt0) (+ y (distance pt2 pt0))))
)
(command "SCALE" (entlast) "" (list 0 Y) (/ 1 tyle))
(command "MVIEW" "O" (entlast))
(if (= (strcase xref) "Y")
(command "xref" "A" xrefFile (list 0 Y) "" "" ""))
(command "MSPACE")
(if (> (distance pt2 pt0) (distance pt1 pt0))
(command "DVIEW" khung "" "TW" (- 90 (* (/ (angle pt0 pt1) pi) 180)) "")
(command "DVIEW" khung "" "TW" (- 0 (* (/ (angle pt0 pt1) pi) 180)) "")
)
(command "ZOOM" "W" pt0 pt3)
(command "PSPACE")
(command "TEXT" "J" "MR" (list -50 (+ Y (/ (distance pt1 pt0) (* 2 tyle)))) (* 25 tyle) "0" (strcat "VP " (rtos (1+ index) 2 0)) "")
(if (> (distance pt2 pt0) (distance pt1 pt0))
(setq Y(- Y 50 (/ (distance pt1 pt0) tyle)))
(setq Y(- Y 50 (/ (distance pt2 pt0) tyle)))
)
(command "ZOOM" "W" (list -100 (+ Y (distance pt3 pt0))) (list (distance pt3 pt0) (- Y 50 (distance pt3 pt0))))
(setq index (+ index 1))
)
(command "ZOOM" "E")
(command "MODEL")
(command "UNDO" "END")
(setvar "OSMODE" os)
(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 #432964 để đọc hướng dẫn và trao đổi thêm.