Jump to content

Lisp lệnh MAT trong chủ đề “Lisp MATTEXT bị lỗi ???”

Update theo yêu cầu: số số lẻ do nguời dùng nhập.

(defun C:mat(/ ent typ nd ss ssle)
 (command "_.undo" "_begin")
 (or vlax-ename->vla-object (vl-load-com))
 (while
   (not
     (and (setq ent (car (nentsel "\nChon doi tuong de lay Text hay Chieu dai :")))
   (setq ent (vlax-ename->vla-object ent))
   (setq typ (vla-get-ObjectName ent))
   (cond
     ((wcmatch typ "*Text,*MLeader,*Attribute")
      (setq nd (vla-get-TextString ent)) )
     ((wcmatch typ "*AttributeDefinition")
      (setq nd (vla-get-TagString ent)) )
     ((wcmatch typ "*Line,*Spline,*Polyline,*Arc,*Circle,*Ellipse")
      (or *ssle* (setq *ssle* 0))
      (initget 4)
      (setq ssle (getint (strcat "\nSo so le <" (itoa *ssle*) ">: ")))
      (if ssle (setq *ssle* ssle))
      (setq nd (rtos (vlax-curve-getDistAtParam ent (vlax-curve-getEndParam ent)) 2 *ssle*)) )
     (t nil)
     ); cond
   ))
   (princ "\nDoi tuong chon khong hop le, Chon lai : "))  
 (princ (strcat"\nChon doi tuong de thay the gia tri Text <" nd "> :" ))
 (if (setq ss (ssget (list (cons 0 "*TEXT,*DIMENSION,MULTILEADER,ATTDEF")) ))
   (foreach ent (vl-remove-if 'listp (mapcar 'cadr (ssnamex ss)))
     (setq ent (vlax-ename->vla-object ent)
    typ (vla-get-ObjectName ent))
     (cond
((wcmatch typ "*Text,*MLeader")	      (vla-put-TextString ent nd) )
((wcmatch typ "*Dimension*")          (vla-put-TextOverride ent nd) )
((wcmatch typ "*AttributeDefinition") (vla-put-TagString ent nd) )
); cond
     )
   )
 (command "_.undo" "_end")
 (princ)
)

Thank you very much.....!!! mình tìm cái líp này vất vả từ lâu. làm kết cấu tuyệt vời.hi

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

  1. Chép mã nguồn, lưu thành tệp 95030_mat.lsp.
  2. 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ẽ.
  3. Gõ lệnh MAT để chạy lisp.

Mã nguồn 95030_mat.lsp (trích từ bài viết gốc)

(defun C:mat(/ ent typ nd ss ssle)
 (command "_.undo" "_begin")
 (or vlax-ename->vla-object (vl-load-com))
 (while
   (not
     (and (setq ent (car (nentsel "\nChon doi tuong de lay Text hay Chieu dai :")))
   (setq ent (vlax-ename->vla-object ent))
   (setq typ (vla-get-ObjectName ent))
   (cond
     ((wcmatch typ "*Text,*MLeader,*Attribute")
      (setq nd (vla-get-TextString ent)) )
     ((wcmatch typ "*AttributeDefinition")
      (setq nd (vla-get-TagString ent)) )
     ((wcmatch typ "*Line,*Spline,*Polyline,*Arc,*Circle,*Ellipse")
      (or *ssle* (setq *ssle* 0))
      (initget 4)
      (setq ssle (getint (strcat "\nSo so le <" (itoa *ssle*) ">: ")))
      (if ssle (setq *ssle* ssle))
      (setq nd (rtos (vlax-curve-getDistAtParam ent (vlax-curve-getEndParam ent)) 2 *ssle*)) )
     (t nil)
     ); cond
   ))
   (princ "\nDoi tuong chon khong hop le, Chon lai : "))  
 (princ (strcat"\nChon doi tuong de thay the gia tri Text <" nd "> :" ))
 (if (setq ss (ssget (list (cons 0 "*TEXT,*DIMENSION,MULTILEADER,ATTDEF")) ))
   (foreach ent (vl-remove-if 'listp (mapcar 'cadr (ssnamex ss)))
     (setq ent (vlax-ename->vla-object ent)
    typ (vla-get-ObjectName ent))
     (cond
((wcmatch typ "*Text,*MLeader")	      (vla-put-TextString ent nd) )
((wcmatch typ "*Dimension*")          (vla-put-TextOverride ent nd) )
((wcmatch typ "*AttributeDefinition") (vla-put-TagString ent nd) )
); cond
     )
   )
 (command "_.undo" "_end")
 (princ)
)

Thảo luận gốc

Lisp được chia sẻ trong chủ đề Lisp MATTEXT bị lỗi ???. Xem đúng bài viết #95030 để đọc hướng dẫn và trao đổi thêm.

Về Thư viện AutoLisp (trang 284)