Lisp lệnh MTBL trong chủ đề “XIN LISP CHÈN TEXT VÀO LINE”
1 giờ trước, hamy2018 đã nói:
(vl-load-com) (defun c:mtbl (/ str hight oldth oldos doc space ss e o a c b line ang p1 p2 p3 p4 mt ) (setq str (getstring "\nNhap text") hight (getreal "\nNhap cao chu") oldth (getvar "textsize") oldos (getvar "osmode") doc (vla-get-activedocument (vlax-get-acad-object)) space (vla-get-modelspace doc)) (setq ss (acet-ss-to-list (ssget '((0 . "LWPOLYLINE,LINE"))))) (SETVAR "textsize" hight) (setvar "osmode" 0) (foreach e ss (setq o (vlax-ename->vla-object e) a (vlax-curve-getstartparam e) c (vlax-curve-getendparam e) b nil Line (wcmatch (vla-get-Objectname o) "AcDbLine") ) (if Line (progn (if b (setq b (1+ b)) (setq b c)) (maketext a) ) (progn (setq demo (rtos (/ c 2))) (if (vl-string-search "." demo)(setq b c)(setq b (- c 1))) (maketext a) ))) (setvar "textsize" oldth) (setvar "osmode" oldos) (vla-regen doc acallviewports) ) (defun maketext (a) (setq p1 (vlax-curve-getpointatparam e a) p2 (vlax-curve-getpointatparam e b) ang (angle p1 p2) p3 (vlax-curve-getpointatparam e (/ (+ b a) 2)) p4 (polar p3 (+ ang (/ pi 2)) (/ hight 2)) ) (vla-addmtext space (vlax-3d-point p4) hight str) (setq mt (entlast)) (vla-put-backgroundfill (vlax-ename->vla-object mt) :vlax-true) )
Sorry, do mình nhìn hình ban đầu của bạn nên lại làm bài toán thêm phức tạp. Lisp của bạn đây
- Tải lisp
- 433508_mtbl.lsp
Cách dùng
- Tải tệp 433508_mtbl.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 MTBL để chạy lisp.
Mã nguồn 433508_mtbl.lsp
;; free lisp from cadviet.com
;;; this lisp was downloaded from https://www.cadviet.com/forum/topic/175170-xin-lisp-ch%C3%A8n-text-v%C3%A0o-line/
(vl-load-com)
(defun c:mtbl (/ str hight oldth oldos doc space ss e o a c b line ang p1 p2 p3 p4 mt )
(setq str (getstring "\nNhap text")
hight (getreal "\nNhap cao chu")
oldth (getvar "textsize")
oldos (getvar "osmode")
doc (vla-get-activedocument (vlax-get-acad-object))
space (vla-get-modelspace doc))
(setq ss (acet-ss-to-list (ssget '((0 . "LWPOLYLINE,LINE")))))
(SETVAR "textsize" hight)
(setvar "osmode" 0)
(foreach e ss
(setq o (vlax-ename->vla-object e)
a (vlax-curve-getstartparam e)
c (vlax-curve-getendparam e)
b nil
Line (wcmatch (vla-get-Objectname o) "AcDbLine")
)
(if Line (progn
(if b (setq b (1+ b))
(setq b c))
(maketext a)
)
(progn
(setq demo (rtos (/ c 2)))
(if (vl-string-search "." demo)(setq b c)(setq b (- c 1)))
(maketext a)
)))
(setvar "textsize" oldth)
(setvar "osmode" oldos)
(vla-regen doc acallviewports)
)
(defun maketext (a)
(setq p1 (vlax-curve-getpointatparam e a)
p2 (vlax-curve-getpointatparam e b)
ang (angle p1 p2)
p3 (vlax-curve-getpointatparam e (/ (+ b a) 2))
p4 (polar p3 (+ ang (/ pi 2)) (/ hight 2))
)
(vla-addmtext space (vlax-3d-point p4) hight str)
(setq mt (entlast))
(vla-put-backgroundfill (vlax-ename->vla-object mt) :vlax-true)
)Thảo luận gốc
Lisp được chia sẻ trong chủ đề XIN LISP CHÈN TEXT VÀO LINE. Xem đúng bài viết #433508 để đọc hướng dẫn và trao đổi thêm.
