Jump to content

Lisp chèn text vào Pl

Về dải text là ok rùi. còn vấn đề này mọi người xem làm thế nào?

có thể chọn text rùi chèn vào 1 chỗ bất kỳ trên pl ko?

Quick code :

(defun c:test(/ curve txtObj pt ang)
(if
(and
 (setq curve (car(entsel "\nCurve:")))
 (setq txtObj (car (entsel "\nText :"))) 
 (setq txtObj (vlax-ename->vla-object txtObj))
 (setq txtObj (vla-copy txtObj))
 (setq pt (vlax-curve-getClosestPointTo curve (trans (getpoint "\nPoint to Insert :") 0 1)))
 (setq ang (angle '(0 0 0) (vlax-curve-getFirstDeriv curve (vlax-curve-getParamAtPoint curve pt))))
 (setq pt (vlax-3d-point pt))
)
(progn
 (if (= (vla-get-Alignment txtObj) 0)
                           	(vla-put-InsertionPoint txtObj pt)
                           	(vla-put-TextAlignmentPoint txtObj pt)
   	)
 (vla-put-Rotation txtObj ang)
)
)
)

Cách dùng

  1. Tải tệp 169583_test.lsp về máy.
  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 TEST để chạy lisp.

Mã nguồn 169583_test.lsp

;; free lisp from cadviet.com
;;; this lisp was downloaded from https://www.cadviet.com/forum/topic/54656-y%C3%AAu-c%E1%BA%A7u-lisp-ch%C3%A8n-text-v%C3%A0o-pl/?tab=comments#comment-169583
(defun c:test(/ curve txtObj pt ang)
(if
(and
 (setq curve (car(entsel "\nCurve:")))
 (setq txtObj (car (entsel "\nText :"))) 
 (setq txtObj (vlax-ename->vla-object txtObj))
 (setq txtObj (vla-copy txtObj))
 (setq pt (vlax-curve-getClosestPointTo curve (trans (getpoint "\nPoint to Insert :") 0 1)))
 (setq ang (angle '(0 0 0) (vlax-curve-getFirstDeriv curve (vlax-curve-getParamAtPoint curve pt))))
 (setq pt (vlax-3d-point pt))
)
(progn
 (if (= (vla-get-Alignment txtObj) 0)
                           	(vla-put-InsertionPoint txtObj pt)
                           	(vla-put-TextAlignmentPoint txtObj pt)
   	)
 (vla-put-Rotation txtObj ang)
)
)
)

Thảo luận gốc

Lisp được chia sẻ trong chủ đề [Yêu cầu] Lisp chèn text vào Pl. Xem đúng bài viết #169583 để đọc hướng dẫn và trao đổi thêm.

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