Lisp lệnh TEST trong chủ đề “Đổi tên của layout”
minhf xin phép sửa lại code cua ketxu theo yeu cầu của Bạn
(defun C:test (/ item *doc* pre after fin rep nam)
;Ketxu
(vl-load-com)
(command "_.undo" "be")
(setq pre (getstring "\nTien to can them vao : ")
after (getstring "\nHau to can them vao : ")
fin (getstring T "\nChuoi can thay the : ")
rep (getstring T "\nChuoi thay the : ")
*doc* (vla-get-layouts(vla-get-activedocument (vlax-get-acad-object)))
)
(foreach lay(layoutlist)
(setq nam (vla-get-name (vla-item *doc* lay)))
(while (vl-string-search fin nam)
(setq nam (vl-string-subst rep fin nam))
)
(vla-put-name (setq item (vla-item *doc* lay)) (strcat pre nam after));(strcat pre (vla-get-name item) after))
)
(command "_.undo" "end")
(princ)
)
@ketxu: Bạn có thể giúp mình thêm đoạn code lấy các layout theo thứ tự được không, việc này có thể thay đổi toàn bộ tên các layout mà không phụ thuộc vào các tên cũ nhưng vẫn đảm bảo tính thứ tự của các layout. Các hàm VLA muốn tìm hiểu thêm thì tìm ở đâu để biết các ứng dụng và cú pháp lệnh, mong Bạn giúp
- Tải lisp
- 201570_test.lsp
Cách dùng
- Tải tệp 201570_test.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 TEST để chạy lisp.
Mã nguồn 201570_test.lsp
;; free lisp from cadviet.com
;;; this lisp was downloaded from https://www.cadviet.com/forum/topic/55539-%C4%91%E1%BB%95i-t%C3%AAn-c%E1%BB%A7a-layout/
(defun C:test (/ item *doc* pre after fin rep nam)
;Ketxu
(vl-load-com)
(command "_.undo" "be")
(setq pre (getstring "\nTien to can them vao : ")
after (getstring "\nHau to can them vao : ")
fin (getstring T "\nChuoi can thay the : ")
rep (getstring T "\nChuoi thay the : ")
*doc* (vla-get-layouts(vla-get-activedocument (vlax-get-acad-object)))
)
(foreach lay(layoutlist)
(setq nam (vla-get-name (vla-item *doc* lay)))
(while (vl-string-search fin nam)
(setq nam (vl-string-subst rep fin nam))
)
(vla-put-name (setq item (vla-item *doc* lay)) (strcat pre nam after));(strcat pre (vla-get-name item) after))
)
(command "_.undo" "end")
(princ)
)
Thảo luận gốc
Lisp được chia sẻ trong chủ đề Đổi tên của layout. Xem đúng bài viết #201570 để đọc hướng dẫn và trao đổi thêm.