Lisp lệnh EDT trong chủ đề “Edit trực tiếp text Attribute trong block”
Trong block có sử dụng nhiều text attribute thì việc gõ ed để sửa nội dung hơi vất vả một chút.
Đây là đoạn code để edit trực tiếp vào các text attribute do ta chọn bằng cách pick chuột.
(defun c:edt () (while (setq att (car(nentsel "\nChon text Attribute :")))(if (= (dxf 0 att) "ATTRIB")(progn (setq TagName (dxf 2 att) TagVal (dxf 1 att) BlName (dxf 330 att)) (if (setq NewVal (getstring 5 (strcat "\nNhap gia tri moi cho " TagName " <" TagVal "> : ")) ) (putAtt BlName TagName NewVal));if);progn);if);while(princ) );end;------------------------------------------------------------------------------------------(defun dxf(id ent) (cdr (assoc id (entget ent))));------------------------------------------------------------------------------------------(defun putAtt (BlName TagName NewVal / AttName EntDxf dk)(setq AttName (entnext BlName ) dk 1) (while (and AttName dk) (if (equal (assoc 0 (entget AttName )) '(0 . "SEQEND")) (setq AttName nil ) (if (= (cdr (assoc 2 (entget AttName ))) TagName ) ; <-- Your Attribute name (progn (setq EntDxf (entget AttName ) dk nil) (setq EntDxf (subst (cons 1 NewVal ) (assoc 1 (entget AttName )) EntDxf ) ) (entmod EntDxf ) (entupd BlName ) (setq AttName (entnext AttName )) );progn (setq AttName (entnext AttName )) );if );if );while );endTuy nhiên lisp này phải gõ nội dung cần thay đổi ở dòng command.Giờ em muốn thực hiện việc này thông qua một hộp thoại. hộp thoại đó có 2 nút Cancel và OK.
Xin nhờ các huynh viết hộ cái này, em không có rành khoản này lắm.
Lisp sử dụng rất đơn giản và tiện. Nhưng có một điều là nếu như ta cùng sửa text ở >1 block khác nhau thì ta lại phải chọn từng cái một. Anh có thể sửa thêm chức năng nữa là cho chọn những text (định sửa có cùng giá trị) sau đó nhập vào không ạ?
- Tải lisp
- 276094_edt.lsp
Cách dùng
- Tải tệp 276094_edt.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 EDT để chạy lisp.
Mã nguồn 276094_edt.lsp
;; free lisp from cadviet.com
;;; this lisp was downloaded from https://www.cadviet.com/forum/topic/13970-edit-tr%E1%BB%B1c-ti%E1%BA%BFp-text-attribute-trong-block/?page=2&tab=comments#comment-448625
(defun c:edt () (while (setq att (car(nentsel "\nChon text Attribute :")))(if (= (dxf 0 att) "ATTRIB")(progn (setq TagName (dxf 2 att) TagVal (dxf 1 att) BlName (dxf 330 att)) (if (setq NewVal (getstring 5 (strcat "\nNhap gia tri moi cho " TagName " <" TagVal "> : ")) ) (putAtt BlName TagName NewVal));if);progn);if);while(princ) );end;------------------------------------------------------------------------------------------(defun dxf(id ent) (cdr (assoc id (entget ent))));------------------------------------------------------------------------------------------(defun putAtt (BlName TagName NewVal / AttName EntDxf dk)(setq AttName (entnext BlName ) dk 1) (while (and AttName dk) (if (equal (assoc 0 (entget AttName )) '(0 . "SEQEND")) (setq AttName nil ) (if (= (cdr (assoc 2 (entget AttName ))) TagName ) ; <-- Your Attribute name (progn (setq EntDxf (entget AttName ) dk nil) (setq EntDxf (subst (cons 1 NewVal ) (assoc 1 (entget AttName )) EntDxf ) ) (entmod EntDxf ) (entupd BlName ) (setq AttName (entnext AttName )) );progn (setq AttName (entnext AttName )) );if );if );while );endThảo luận gốc
Lisp được chia sẻ trong chủ đề Edit trực tiếp text Attribute trong block. Xem đúng bài viết #276094 để đọc hướng dẫn và trao đổi thêm.