Jump to content

H?i V? ???ng Th?ng Khi Có T?a ?? Trên S? ??

B?n th? cái này xem:
(defun C:RGT (/ MKTEXT tmp Plist mspace obj ent epar j len pal le1 le2 Pm lst ang)
;;--- NHAP TOA DO CAC DIEM O DAY :
(setq Plist (list '(1204372.51 610950.64) '(1204367.73 610979.33) '(1204360.41 610976.53) '(1204358.58 610981.01) '(1204357.31 610984.12)
'(1204341.11 610977.91) '(1204342.47 610974.65) '(1204343.94 610971.56) '(1204354.13 610946.60) '(1204372.51 610950.64)))
;;-----------------------------------------------------------------------------------------------------------------------------------------
(defun MKTEXT (pt hgt str ang col)
(if (and pt str)
(entmakex (list (cons 0 "TEXT")
(cons 10 pt)
(cons 40 hgt)
(cons 50 ang)
(cons 62 col)
(cons 1 str)
(cons 72 1)
(cons 11 pt)
(cons 73 2)))))
(vl-load-com)
(setq mspace (vla-get-modelSpace (vla-get-activeDocument (vlax-get-acad-object))))
(setq Plist (apply 'append Plist))
(setq tmp (vlax-make-safearray vlax-vbDouble (cons 0 (- (vl-list-length Plist) 1))))
(vlax-safearray-fill tmp Plist)
(setq obj (vla-addLightweightPolyline mspace tmp)
ent (vlax-vla-object->ename obj))
(vla-put-color obj 3)
(setq epar (vlax-curve-getendparam obj)
j -1
pal (vlax-curve-getdistatparam obj epar))
(repeat (fix epar)
(setq j (1+ j)
le1 (vlax-curve-getdistatparam obj j)
le2 (vlax-curve-getdistatparam obj (1+ j))
len (- le2 le1)
Pm (trans (vlax-curve-getPointAtParam ent (+ j 0.5)) 0 ent)
ang (angle (trans (vlax-curve-getpointatparam ent j) 0 ent)
(trans (vlax-curve-getpointatparam ent (1+ j)) 0 ent))
lst (cons (list (1+ j) Pm len) lst))
(MKTEXT (trans (vlax-curve-getpointatparam ent j) 0 ent) 0.75 (itoa (1+ j)) 0 1)
(cond ((and (> ang (/ pi 2)) (<= ang pi)) (setq ang (- ang pi)))
((and (> ang pi) (<= ang (/ (* 3 pi) 2))) (setq ang (+ ang pi))))
(MKTEXT Pm 0.5 (rtos len 2 2) ang 2))
(princ))

Cách dùng

  1. Tải tệp 380727_rgt.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 RGT để chạy lisp.

Mã nguồn 380727_rgt.lsp

;; free lisp from cadviet.com
;;; this lisp was downloaded from https://www.cadviet.com/forum/topic/148123-h%E1%BB%8Fi-v%E1%BA%BD-%C4%91%C6%B0%E1%BB%9Dng-th%E1%BA%B3ng-khi-c%C3%B3-t%E1%BB%8Da-%C4%91%E1%BB%99-tr%C3%AAn-s%E1%BB%95-%C4%91%E1%BB%8F/
(defun C:RGT (/ MKTEXT tmp Plist mspace obj ent epar j len pal le1 le2 Pm lst ang)

Thảo luận gốc

Lisp được chia sẻ trong chủ đề Hỏi Vẽ Đường Thẳng Khi Có Tọa Độ Trên Sổ Đỏ. Xem đúng bài viết #380727 để đọc hướng dẫn và trao đổi thêm.

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