Lisp lệnh MD trong chủ đề “Lisp Đóng Mở Ngoặc Text, Mtext, Dim”
Bạn thử Lisp này:
(vl-load-com) (defun Tue-string-replace (Lst / i find rep str icase) ;;;;;write by Tue_NV (setq i 0) (mapcar 'set '(find rep str icase) Lst) (while (setq i (vl-string-search (if icase (strcase find) find) (if icase (strcase str) str) i)) (if icase (setq str (vl-string-subst (strcase find) find str i) str (vl-string-subst rep (strcase find) str i)) (setq str (vl-string-subst rep find str i)) ) (setq i (+ i (strlen rep) ) ) ) str) (defun Tue-ent-mod (dxf ename newValue / entget-ename) (setq entget-ename (entget ename)) (if (and (or (= dxf 62) (= dxf 6)) (null (assoc dxf entget-ename))) (setq entget-ename (append entget-ename (list (cons dxf newValue)))) ) (setq entget-ename (subst (cons dxf newValue) (assoc dxf entget-ename) entget-ename)) (entmod entget-ename) ename ) (defun c:md() (if (setq ss (ssget '((0 . "*TEXT,*DIMENSION")))) (progn (setq i -1) (while (setq e (ssname ss (setq i (1+ i)))) (if (and (wcmatch (setq nd (cdr(assoc 1 (entget e)))) "*(*") (wcmatch nd "*)*") ) (Tue-ent-mod 1 e (Tue-string-replace (list ")" "" (Tue-string-replace (list "(" "" nd))))) (Tue-ent-mod 1 e (strcat "(" nd ")")) ) ) )) )
Hai lsp của bạn và rất đúng với ý mình rồi, nhưng 2 lso này chưa chọn được đối tượng là dim. Mong hai bạn giúp thêm
Tệp .lsp gốc không còn trên máy chủ. Hãy chép mã nguồn bên dưới (lấy từ bài viết gốc) vào một tệp văn bản, lưu với đuôi .lsp.
Cách dùng
- Chép mã nguồn, lưu thành tệp 405318_md.lsp.
- 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 MD để chạy lisp.
Mã nguồn 405318_md.lsp (trích từ bài viết gốc)
(vl-load-com)
(defun Tue-string-replace (Lst / i find rep str icase)
;;;;;write by Tue_NV
(setq i 0)
(mapcar 'set '(find rep str icase) Lst)
(while (setq i (vl-string-search (if icase (strcase find) find)
(if icase (strcase str) str) i))
(if icase
(setq str (vl-string-subst (strcase find) find str i)
str (vl-string-subst rep (strcase find) str i))
(setq str (vl-string-subst rep find str i))
)
(setq i (+ i (strlen rep) ) ) )
str)
(defun Tue-ent-mod (dxf ename newValue / entget-ename)
(setq entget-ename (entget ename))
(if (and (or (= dxf 62) (= dxf 6)) (null (assoc dxf entget-ename)))
(setq entget-ename (append entget-ename (list (cons dxf newValue))))
)
(setq entget-ename (subst (cons dxf newValue) (assoc dxf entget-ename) entget-ename))
(entmod entget-ename)
ename
)
(defun c:md()
(if (setq ss (ssget '((0 . "*TEXT,*DIMENSION")))) (progn
(setq i -1)
(while (setq e (ssname ss (setq i (1+ i))))
(if (and (wcmatch (setq nd (cdr(assoc 1 (entget e)))) "*(*")
(wcmatch nd "*)*")
)
(Tue-ent-mod 1 e (Tue-string-replace (list ")" "" (Tue-string-replace (list "(" "" nd)))))
(Tue-ent-mod 1 e (strcat "(" nd ")"))
)
)
))
)Thảo luận gốc
Lisp được chia sẻ trong chủ đề Lisp Đóng Mở Ngoặc Text, Mtext, Dim. Xem đúng bài viết #405318 để đọc hướng dẫn và trao đổi thêm.