Jump to content

Lisp lệnh FD trong chủ đề “Xin chỉ giúp tử mm ra meter !”

3 giờ trước, nguyenvinh5779 đã nói:

Xin cám ơn bạn

nhưng sao không dược bạn oi !

nho bạn chỉnh giúp  !

có thể chỉnh chiều cao chữ bằng cách chọn 02 điểm trên màn hình khong ?

xin cám on ban !

(defun C:fd( / ss L e #h)
(vl-load-com)
(setq ent (car (entsel "\nChon text lay chieu cao text")))
(setq #h (cdr (assoc 40 (entget ent))))

(defun Length1(e) (/ (vlax-curve-getDistAtParam e (vlax-curve-getEndParam e)) 1000))
(or ans (setq ans 1))
(setq
   #h 200
   L (strcat "L : "
   (vl-princ-to-string (* (getvar "dimlfac") (apply '+
       (mapcar 'Length1 (vl-remove-if 'listp (mapcar 'cadr (ssnamex (ssget (list (cons 0 "LINE,ARC,CIRCLE,POLYLINE,LWPOLYLINE,ELLIPSE,SPLINE")))))))))) "m"))
   (setq
   ans (cond ((getint (strcat "\nPhuong an nhap ket qua < " (itoa ans) " > :")))(ans))
   txtObj (cond     ((= ans 1) (vlax-ename->vla-object (car (entsel "\nChon text ghi ket qua :"))))
                   (T (vla-addtext (vla-get-modelspace (vla-get-activedocument (vlax-get-acad-object))) L (vlax-3d-point (getpoint "\n Chon diem nhap ket qua" )) #h ))))
(vla-put-TextString txtObj L)
(vla-put-Height txtObj #h)
(princ))

mình thấy bạn sửa ở trên là xoa #h rồi nên mình chỉ nói thay phần trên, bạn lại thêm #h phía dưới

Sửa lại cho bạn lấy chiểu cao chữ theo chữ mẫu

(defun C:fd( / ss L e #h)
(vl-load-com)
(setq ent (car (entsel "\nChon text lay chieu cao text")))
(setq #h (cdr (assoc 40 (entget ent))))
(defun Length1(e) (/ (vlax-curve-getDistAtParam e (vlax-curve-getEndParam e)) 1000))
(or ans (setq ans 1))
(setq
   L (strcat "L : "
   (vl-princ-to-string (* (getvar "dimlfac") (apply '+
       (mapcar 'Length1 (vl-remove-if 'listp (mapcar 'cadr (ssnamex (ssget (list (cons 0 "LINE,ARC,CIRCLE,POLYLINE,LWPOLYLINE,ELLIPSE,SPLINE")))))))))) "m"))
   (setq
   ans (cond ((getint (strcat "\nPhuong an nhap ket qua < " (itoa ans) " > :")))(ans))
   txtObj (cond     ((= ans 1) (vlax-ename->vla-object (car (entsel "\nChon text ghi ket qua :"))))
                   (T (vla-addtext (vla-get-modelspace (vla-get-activedocument (vlax-get-acad-object))) L (vlax-3d-point (getpoint "\n Chon diem nhap ket qua" )) #h ))))
(vla-put-TextString txtObj L)
(vla-put-Height txtObj #h)
(princ))

Cách dùng

  1. Tải tệp 463187_fd.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 FD để chạy lisp.

Mã nguồn 463187_fd.lsp

;; free lisp from cadviet.com
;;; this lisp was downloaded from https://www.cadviet.com/forum/topic/191769-xin-ch%E1%BB%89-gi%C3%BAp-t%E1%BB%AD-mm-ra-meter/
(defun C:fd( / ss L e #h)
(vl-load-com)
(setq ent (car (entsel "\nChon text lay chieu cao text")))
(setq #h (cdr (assoc 40 (entget ent))))
(defun Length1(e) (/ (vlax-curve-getDistAtParam e (vlax-curve-getEndParam e)) 1000))
(or ans (setq ans 1))
(setq
   L (strcat "L : "
   (vl-princ-to-string (* (getvar "dimlfac") (apply '+
       (mapcar 'Length1 (vl-remove-if 'listp (mapcar 'cadr (ssnamex (ssget (list (cons 0 "LINE,ARC,CIRCLE,POLYLINE,LWPOLYLINE,ELLIPSE,SPLINE")))))))))) "m"))
   (setq
   ans (cond ((getint (strcat "\nPhuong an nhap ket qua < " (itoa ans) " > :")))(ans))
   txtObj (cond     ((= ans 1) (vlax-ename->vla-object (car (entsel "\nChon text ghi ket qua :"))))
                   (T (vla-addtext (vla-get-modelspace (vla-get-activedocument (vlax-get-acad-object))) L (vlax-3d-point (getpoint "\n Chon diem nhap ket qua" )) #h ))))
(vla-put-TextString txtObj L)
(vla-put-Height txtObj #h)
(princ))

Thảo luận gốc

Lisp được chia sẻ trong chủ đề Xin chỉ giúp tử mm ra meter !. Xem đúng bài viết #463187 để đọc hướng dẫn và trao đổi thêm.

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