Lisp tạo viewport từ khung chọn bên model
(defun Makepline (listpoint closed Layer Linetype LTScale xdata / Lst)
(setq Lst (list '(0 . "LWPOLYLINE")'(100 . "AcDbEntity")
(cons 8 (if Layer Layer (getvar "Clayer")))
(cons 6 (if Linetype Linetype "bylayer"))
(cons 48 (if LTScale LTScale 1))
'(100 . "AcDbPolyline")
(cons 90 (length listpoint))
(cons 70 (if closed 1 0))))
(foreach PP listpoint (setq Lst (append Lst (list (cons 10 PP)))))
(if xdata (setq Lst (append lst (list (cons -3 (list xdata))))))
(entmakex Lst))
;end;=================================
;;;;;;;;;;
(defun _layer2 ( name colour )
(if (null (tblsearch "LAYER" name))
(entmake
(list
'(0 . "LAYER")
'(100 . "AcDbSymbolTableRecord")
'(100 . "AcDbLayerTableRecord")
'(70 . 0)
(cons 2 name)
(cons 62 colour)
)
)
)
)
; ham luu gia tri
(defun getvalue ( a giatri dongnhac / astr)
(or a (setq a giatri))
(cond
((= (type a) 'INT) (setq a (cond ((getint (strcat "\n" dongnhac "(" (itoa a) ") :")))(a))))
((= (type a) 'REAL) (setq a (cond ((getreal (strcat "\n" dongnhac "(" (rtos a 2 0) ") :")))(a))))
((= (type a) 'STR) (setq a (cond ((= "" (setq astr (getstring 1 (strcat "\n" dongnhac " (" a "): ")))) a) (astr))))
))
;;;;
;============================================================
;========LISP TAO VIEWPORT TREN LAYOUT BANG CACH CHON O MODEL========
;=========================REV4ii=====================================
(defun C:mtll( / os lst khung X_min Y_min X_max Y_max X index taphop pt1)
(vl-load-com)
(if (null (tblsearch "LAYER" "khung")) (_layer2 "Khung" 3))
(command "UNDO" "BE")
(setq os(getvar "OSMODE"))
(setvar "OSMODE" 0)
(while (/= (setq taphop (ssget "+.:E:S" '((0 . "LWPOLYLINE")))) nil)
(progn
(setq tyleVT (getvalue tyleVT 1000.0 "Nhap ty le ban do: "))
(command "LAYOUT" "S" "Layout1")
(setq pt1 (getpoint "\nchon diem dat khung"))
(command "ZOOM" "E")
(setq khung (ssname taphop 0))
(setq lst (cdr (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" "Layout1")
(command "ZOOM" "W" (list X_min Y_min) (list X_max Y_max))
(makepline lst 1 "Khung" nil nil nil)
(command "MOVE" (entlast) "" (list X_min Y_min) (list (car pt1) 0))
(command "ZOOM" "W" (list 0 0) (list (+ (car pt1) 100) 0))
(command "SCALE" (entlast) "" (list (car pt1) 0) (/ 1000 tyleVT))
(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) "")
(command "ZOOM" "W" (list 0 0) (list (+ (car pt1) 100) 0))
(command "MODEL")
) ;ene progn while
) ; end while
(command "MODEL")
(command "UNDO" "END")
(setvar "OSMODE" os)
(princ)
)
;=======================================================
Mình tìm được 1 lsp về tạo viewport từ khung chọn bên model trong topic này https://www.cadviet.com/forum/topic/68723-yeu-cau-lisp-tao-viewport-tu-khung-chon-ben-model/page-6
lsp #109 của nhoclangbat rất gần với nhu cầu làm việc của mình, mình muốn nhờ bạn nào biết về lsp sửa giúp cho phù hợp với mình.
Mình muốn sửa cách thức nhập tỷ lệ cho viewport khi lsp yêu cầu nhập tỷ lệ ở dòng command ( vd tỷ lệ 1/50 thì nhập là 1/50, tỷ lệ 2/1 thì nhập là 2/1 )
Thứ 2 là tỷ lệ của viewport, ( mình dùng lsp này thấy có vẻ như tác giả scale khung viewport lên n lần theo cái tỷ lệ nhập vào khi lsp yêu cầu ) giờ mình muốn sửa lại là cái viewport đc tạo ra bên layout y nguyên cái khung bên model.
Nhân tiện có cách nào để chỉnh linetype của khung viewport thành nét đứt đc không ?
- Tải lisp
- 361854_mtll.lsp
Cách dùng
- Tải tệp 361854_mtll.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 MTLL để chạy lisp.
Mã nguồn 361854_mtll.lsp
;; free lisp from cadviet.com
;;; this lisp was downloaded from https://www.cadviet.com/forum/topic/139310-nh%E1%BB%9D-c%C3%A1c-b%E1%BA%A1n-gi%C3%BAp-%C4%91%E1%BB%A1-s%E1%BB%ADa-lisp/
(defun Makepline (listpoint closed Layer Linetype LTScale xdata / Lst)
(setq Lst (list '(0 . "LWPOLYLINE")'(100 . "AcDbEntity")
(cons 8 (if Layer Layer (getvar "Clayer")))
(cons 6 (if Linetype Linetype "bylayer"))
(cons 48 (if LTScale LTScale 1))
'(100 . "AcDbPolyline")
(cons 90 (length listpoint))
(cons 70 (if closed 1 0))))
(foreach PP listpoint (setq Lst (append Lst (list (cons 10 PP)))))
(if xdata (setq Lst (append lst (list (cons -3 (list xdata))))))
(entmakex Lst))
;end;=================================
;;;;;;;;;;
(defun _layer2 ( name colour )
(if (null (tblsearch "LAYER" name))
(entmake
(list
'(0 . "LAYER")
'(100 . "AcDbSymbolTableRecord")
'(100 . "AcDbLayerTableRecord")
'(70 . 0)
(cons 2 name)
(cons 62 colour)
)
)
)
)
; ham luu gia tri
(defun getvalue ( a giatri dongnhac / astr)
(or a (setq a giatri))
(cond
((= (type a) 'INT) (setq a (cond ((getint (strcat "\n" dongnhac "(" (itoa a) ") :")))(a))))
((= (type a) 'REAL) (setq a (cond ((getreal (strcat "\n" dongnhac "(" (rtos a 2 0) ") :")))(a))))
((= (type a) 'STR) (setq a (cond ((= "" (setq astr (getstring 1 (strcat "\n" dongnhac " (" a "): ")))) a) (astr))))
))
;;;;
;============================================================
;========LISP TAO VIEWPORT TREN LAYOUT BANG CACH CHON O MODEL========
;=========================REV4ii=====================================
(defun C:mtll( / os lst khung X_min Y_min X_max Y_max X index taphop pt1)
(vl-load-com)
(if (null (tblsearch "LAYER" "khung")) (_layer2 "Khung" 3))
(command "UNDO" "BE")
(setq os(getvar "OSMODE"))
(setvar "OSMODE" 0)
(while (/= (setq taphop (ssget "+.:E:S" '((0 . "LWPOLYLINE")))) nil)
(progn
(setq tyleVT (getvalue tyleVT 1000.0 "Nhap ty le ban do: "))
(command "LAYOUT" "S" "Layout1")
(setq pt1 (getpoint "\nchon diem dat khung"))
(command "ZOOM" "E")
(setq khung (ssname taphop 0))
(setq lst (cdr (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" "Layout1")
(command "ZOOM" "W" (list X_min Y_min) (list X_max Y_max))
(makepline lst 1 "Khung" nil nil nil)
(command "MOVE" (entlast) "" (list X_min Y_min) (list (car pt1) 0))
(command "ZOOM" "W" (list 0 0) (list (+ (car pt1) 100) 0))
(command "SCALE" (entlast) "" (list (car pt1) 0) (/ 1000 tyleVT))
(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) "")
(command "ZOOM" "W" (list 0 0) (list (+ (car pt1) 100) 0))
(command "MODEL")
) ;ene progn while
) ; end while
(command "MODEL")
(command "UNDO" "END")
(setvar "OSMODE" os)
(princ)
)
;======================================================= Thảo luận gốc
Lisp được chia sẻ trong chủ đề Nhờ các bạn giúp đỡ sửa lisp. Xem đúng bài viết #361854 để đọc hướng dẫn và trao đổi thêm.