Jump to content

Lisp lệnh TCDT trong chủ đề “Nhờ các bác chỉnh giùm em lisp ghi chiều dài đoạn polyline vào block attributes”

@vanhuyou Bạn dùng thử

(defun c:tcdt (/ att ent len ss)
  (setvar 'DIMZIN 0)
  (and (setq ss (ssget "_+.:S:E" '((0 . "*LINE"))))
       (setq ent (ssname ss 0))
       (not (redraw ent 3))
       (setq att (car (nentsel "\nPick Att: ")))
       (eq (cdr (assoc 0 (entget att))) "ATTRIB")
       (setq
	 len (vlax-curve-getDistAtParam ent (vlax-curve-getEndParam ent))
       ) ;_ end of setq
       (not
	 (vla-put-textstring
	   (vlax-ename->vla-object att)
	   (strcat (vla-get-textstring (vlax-ename->vla-object att))
		   " - "
		   (rtos len 2 0)
	   ) ;_ end of strcat
	 ) ;_ end of vla-put-textstring
       ) ;_ end of not
       (redraw ent 4)
  ) ;_ end of and
  (princ)
) ;_ end of defun

 

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 445542_tcdt.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 TCDT để chạy lisp.

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

(defun c:tcdt (/ att ent len ss)
  (setvar 'DIMZIN 0)
  (and (setq ss (ssget "_+.:S:E" '((0 . "*LINE"))))
       (setq ent (ssname ss 0))
       (not (redraw ent 3))
       (setq att (car (nentsel "\nPick Att: ")))
       (eq (cdr (assoc 0 (entget att))) "ATTRIB")
       (setq
	 len (vlax-curve-getDistAtParam ent (vlax-curve-getEndParam ent))
       ) ;_ end of setq
       (not
	 (vla-put-textstring
	   (vlax-ename->vla-object att)
	   (strcat (vla-get-textstring (vlax-ename->vla-object att))
		   " - "
		   (rtos len 2 0)
	   ) ;_ end of strcat
	 ) ;_ end of vla-put-textstring
       ) ;_ end of not
       (redraw ent 4)
  ) ;_ end of and
  (princ)
) ;_ end of defun

Thảo luận gốc

Lisp được chia sẻ trong chủ đề Nhờ các bác chỉnh giùm em lisp ghi chiều dài đoạn polyline vào block attributes. Xem đúng bài viết #445542 để đọc hướng dẫn và trao đổi thêm.

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