Jump to content

Lisp lệnh NSUY trong chủ đề “nội suy cao độ đường cong”


Bạn dùng lệnh UN để chỉnh số lẻ thập phân rồi dùng Lisp này :

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 195807_nsuy.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 NSUY để chạy lisp.

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

(defun c:nsuy(/ curve p1 Z1 p2 Z2 cao dis Hz tana a chontext)
(defun chontext()
(entget(car(entsel "\nChon Text :")))
)
 (setq curve (car(entsel "\n Chon Curve :")))
 (setq p1 (getpoint "\n Nhap diem P1 :"))
(initget "")
 (setq Z1 (getreal "\n Nhap cao do Z1 / Nhan Enter de chon Text :"))
 (if (null Z1)  (setq text (chontext) cao (cdr(assoc 40 text)) Z1 (atof (cdr(assoc 1 text)))  ) )

 (setq p2 (getpoint p1 "\n Nhap diem P2 :"))
(initget "")
 (setq Z2 (getreal "\n Nhap cao do Z2 / Nhan Enter de chon Text :"))
 (if (null Z2)  (setq text (chontext) cao (cdr(assoc 40 text)) Z2 (atof (cdr(assoc 1 text)))  ) )

 (if (not cao) (setq cao (getdist "\n Nhap chieu cao chu :")))

 (setq dis (abs (- (vlax-curve-getdistatpoint curve p1) (vlax-curve-getdistatpoint curve p2))))
 (setq Hz (- Z1 Z2) tana (abs (/ Hz dis)))

(While (setq p (getpoint p1 "\n Nhap diem P / Enter ket thuc lenh :"))
(if (< Z1 Z2)
  (if (< (vlax-curve-getparamatpoint curve p1)  (vlax-curve-getparamatpoint curve p2))
   (progn (setq a (- (vlax-curve-getdistatpoint curve p) (vlax-curve-getdistatpoint curve p1))
   Z (+ Z1 (* tana a))) )
   (progn (setq a (- (vlax-curve-getdistatpoint curve p1) (vlax-curve-getdistatpoint curve p))
   Z (+ Z1 (* tana a)))  )
  )
)
(if (> Z1 Z2)
  (if (< (vlax-curve-getparamatpoint curve p1)  (vlax-curve-getparamatpoint curve p2))
 (progn (setq a (- (vlax-curve-getdistatpoint curve p2) (vlax-curve-getdistatpoint curve p))
   Z (+ Z2 (* tana a)))  )
 (progn (setq a (- (vlax-curve-getdistatpoint curve p) (vlax-curve-getdistatpoint curve p2))
   Z (+ Z2 (* tana a)))  )
  )
)
(princ Z)
 );while
(princ)
)

Thảo luận gốc

Lisp được chia sẻ trong chủ đề nội suy cao độ đường cong. Xem đúng bài viết #195807 để đọc hướng dẫn và trao đổi thêm.

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