lisp tạo tỉ lệ cho viewport bên layout
Quick code và không bắt lỗi, bạn dùng tạm. Có tỉ lệ nào thì bạn thêm vào mục Scale
Code có sử dụng hàm LM:Listbox của LeeMac cho nhanh
(vl-load-com) (defun c:vps(/ l sc LM:ListBox) ;; Private function : (defun LM:ListBox ( title data multiple / file tmp dch return ) (cond ( (not (and (setq file (open (setq tmp (vl-filename-mktemp nil nil ".dcl")) "w")) (write-line (strcat "listbox : dialog { label = \"" title "\"; spacer; : list_box { key = \"list\"; multiple_select = " (if multiple "true" "false") "; } spacer; ok_cancel;}" ) file ) (not (close file)) (< 0 (setq dch (load_dialog tmp))) (new_dialog "listbox" dch) ) ) ) ( t (start_list "list") (mapcar 'add_list data) (end_list) (setq return (set_tile "list" "0")) (action_tile "list" "(setq return $value)") (setq return (if (= 1 (start_dialog)) (mapcar '(lambda ( x ) (nth x data)) (read (strcat "(" return ")"))) ) ) ) ) (if (< 0 dch) (unload_dialog dch)) (if (setq tmp (findfile tmp)) (vl-file-delete tmp)) return ) ;Main (ssget '((0 . "VIEWPORT"))) (setq l '("1/2" "1/5" "1/10")) ;Scale them o day (setq sc (distof (car (LM:listbox "Select Scale :" l nil)))) (vlax-for vp (vla-get-activeselectionset (vla-get-activedocument (vlax-get-acad-object))) (vla-put-DisplayLocked vp 0) (vla-put-CustomScale vp sc) ) )
Mình dùng thử và thấy lisp này thế là phù hợp với mình rồi
Cám ơn bạn ketxu nhiều nhé :D
- Tải lisp
- 310756_vps.lsp
Cách dùng
- Tải tệp 310756_vps.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 VPS để chạy lisp.
Mã nguồn 310756_vps.lsp
;; free lisp from cadviet.com
;;; this lisp was downloaded from https://www.cadviet.com/forum/topic/109745-y%C3%AAu-c%E1%BA%A7u-lisp-t%E1%BA%A1o-t%E1%BB%89-l%E1%BB%87-cho-viewport-b%C3%AAn-layout/
(vl-load-com)
(defun c:vps(/ l sc LM:ListBox)
;; Private function :
(defun LM:ListBox ( title data multiple / file tmp dch return )
(cond
(
(not
(and (setq file (open (setq tmp (vl-filename-mktemp nil nil ".dcl")) "w"))
(write-line
(strcat "listbox : dialog { label = \"" title
"\"; spacer; : list_box { key = \"list\"; multiple_select = "
(if multiple "true" "false") "; } spacer; ok_cancel;}"
)
file
)
(not (close file)) (< 0 (setq dch (load_dialog tmp))) (new_dialog "listbox" dch)
)
)
)
(
t
(start_list "list")
(mapcar 'add_list data) (end_list)
(setq return (set_tile "list" "0"))
(action_tile "list" "(setq return $value)")
(setq return
(if (= 1 (start_dialog))
(mapcar '(lambda ( x ) (nth x data)) (read (strcat "(" return ")")))
)
)
)
)
(if (< 0 dch) (unload_dialog dch))
(if (setq tmp (findfile tmp)) (vl-file-delete tmp))
return
)
;Main
(ssget '((0 . "VIEWPORT")))
(setq l '("1/2" "1/5" "1/10")) ;Scale them o day
(setq sc (distof (car (LM:listbox "Select Scale :" l nil))))
(vlax-for vp (vla-get-activeselectionset (vla-get-activedocument (vlax-get-acad-object)))
(vla-put-DisplayLocked vp 0)
(vla-put-CustomScale vp sc)
)
)Thảo luận gốc
Lisp được chia sẻ trong chủ đề [yêu cầu] lisp tạo tỉ lệ cho viewport bên layout. Xem đúng bài viết #310756 để đọc hướng dẫn và trao đổi thêm.