Lisp lệnh NS trong chủ đề “Nội suy cao độ trên chiếu bằng”
Uhm, thì tạo text vậy ^^
;lisp noi suy (defun c:NS( / CD CD1 CD2 DIS1 DIS2 LST_VA OLD PL1 PL2 PT TEXT1 TEXT2) (vl-load-com) (setq lst_va '("osmode" "cmdecho")) (setq old (mapcar 'getvar lst_va)) (mapcar 'setvar lst_va '(4 0)) (setq pl1 (car (entsel "\n Chon dinh (hoac chan) ta luy: ")) text1 (car (entsel "\n Chon text cao do tuong ung: ")) pl2 (car (entsel "\n Chon chan (hoac dinh) ta luy: ")) text2 (car (entsel "\n Chon text cao do tuong ung: ")) ) (if (and pl1 pl2 text2 text2) (progn (setq cd1 (atof (Replace_First_Comma_by_Dot (cdr (assoc 1 (entget text1))))) cd2 (atof (Replace_First_Comma_by_Dot (cdr (assoc 1 (entget text2))))) ; pl1 (vlax-ename->vla-object pl1) ; pl2 (vlax-ename->vla-object pl2) ) (while (setq pt (getpoint "\n Pick diem can noi suy cao do <Enter de thoat>: ")) (setq pt (reverse (cdr (reverse pt))) dis1 (distance pt (vlax-curve-getClosestPointTo pl1 pt)) dis2 (distance pt (vlax-curve-getClosestPointTo pl2 pt)) cd (+ cd1 (* dis1 (/ (- cd2 cd1) (+ dis1 dis2)))) ) (princ (strcat "\n Cao do tai diem nay la: " (rtos cd 2 4))) (MakeText (trans pt 1 0) (rtos cd 2 2) 1 0 "L" nil nil nil nil) ) ) (princ "\n Bam lung tung roi ^^ Lam lai!") ) ;;xong tra ve: (mapcar 'setvar lst_va old) (princ) ) ;;;=================================== (defun Replace_First_Comma_by_Dot (string_with_comma / STR STR1 STR2 VT) (cond ((setq vt (vl-string-position (ascii ",") string_with_comma)) (setq str1 (substr string_with_comma 1 vt) str2 (substr string_with_comma (+ vt 2)) str (strcat str1 "." str2) ) ) (t (setq str string_with_comma)) ) ) ;;;======================================= (defun MakeText (point string Height Ang justify Style Layer Color xdata / Lst) ; Ang: Radial (setq Lst (list '(0 . "TEXT") (cons 8 (if Layer Layer (getvar "Clayer"))) (cons 62 (if Color Color 256)) (cons 10 point) (cons 40 Height) (cons 1 string) (if Ang (cons 50 Ang)) (cons 7 (if Style Style (getvar "Textstyle"))) (cons -3 (if xdata (list xdata) nil))) justify (strcase justify)) (cond ((= justify "C") (setq Lst (append Lst (list (cons 72 1) (cons 11 point))))) ((= justify "R") (setq Lst (append Lst (list (cons 72 2) (cons 11 point))))) ((= justify "M") (setq Lst (append Lst (list (cons 72 4) (cons 11 point))))) ((= justify "TL") (setq Lst (append Lst (list (cons 72 0) (cons 11 point) (cons 73 3))))) ((= justify "TC") (setq Lst (append Lst (list (cons 72 1) (cons 11 point) (cons 73 3))))) ((= justify "TR") (setq Lst (append Lst (list (cons 72 2) (cons 11 point) (cons 73 3))))) ((= justify "ML") (setq Lst (append Lst (list (cons 72 0) (cons 11 point) (cons 73 2))))) ((= justify "MC") (setq Lst (append Lst (list (cons 72 1) (cons 11 point) (cons 73 2))))) ((= justify "MR") (setq Lst (append Lst (list (cons 72 2) (cons 11 point) (cons 73 2))))) ((= justify "BL") (setq Lst (append Lst (list (cons 72 0) (cons 11 point) (cons 73 1))))) ((= justify "BC") (setq Lst (append Lst (list (cons 72 1) (cons 11 point) (cons 73 1))))) ((= justify "BR") (setq Lst (append Lst (list (cons 72 2) (cons 11 point) (cons 73 1))))) ) (entmakex Lst) );end
- Tải lisp
- 424347_ns.lsp
Cách dùng
- Tải tệp 424347_ns.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 NS để chạy lisp.
Mã nguồn 424347_ns.lsp
;; free lisp from cadviet.com
;;; this lisp was downloaded from https://www.cadviet.com/forum/topic/171645-n%E1%BB%99i-suy-cao-%C4%91%E1%BB%99-tr%C3%AAn-chi%E1%BA%BFu-b%E1%BA%B1ng/
;lisp noi suy
(defun c:NS( / CD CD1 CD2 DIS1 DIS2 LST_VA OLD PL1 PL2 PT TEXT1 TEXT2)
(vl-load-com)
(setq lst_va '("osmode" "cmdecho"))
(setq old (mapcar 'getvar lst_va))
(mapcar 'setvar lst_va '(4 0))
(setq pl1 (car (entsel "\n Chon dinh (hoac chan) ta luy: "))
text1 (car (entsel "\n Chon text cao do tuong ung: "))
pl2 (car (entsel "\n Chon chan (hoac dinh) ta luy: "))
text2 (car (entsel "\n Chon text cao do tuong ung: "))
)
(if (and pl1 pl2 text2 text2)
(progn
(setq cd1 (atof (Replace_First_Comma_by_Dot (cdr (assoc 1 (entget text1)))))
cd2 (atof (Replace_First_Comma_by_Dot (cdr (assoc 1 (entget text2)))))
; pl1 (vlax-ename->vla-object pl1)
; pl2 (vlax-ename->vla-object pl2)
)
(while
(setq pt (getpoint "\n Pick diem can noi suy cao do <Enter de thoat>: "))
(setq pt (reverse (cdr (reverse pt)))
dis1 (distance pt (vlax-curve-getClosestPointTo pl1 pt))
dis2 (distance pt (vlax-curve-getClosestPointTo pl2 pt))
cd (+ cd1 (* dis1 (/ (- cd2 cd1) (+ dis1 dis2))))
)
(princ (strcat "\n Cao do tai diem nay la: " (rtos cd 2 4)))
(MakeText (trans pt 1 0) (rtos cd 2 2) 1 0 "L" nil nil nil nil)
)
)
(princ "\n Bam lung tung roi ^^ Lam lai!")
)
;;xong tra ve:
(mapcar 'setvar lst_va old)
(princ)
)
;;;===================================
(defun Replace_First_Comma_by_Dot (string_with_comma / STR STR1 STR2 VT)
(cond
((setq vt (vl-string-position (ascii ",") string_with_comma))
(setq str1 (substr string_with_comma 1 vt)
str2 (substr string_with_comma (+ vt 2))
str (strcat str1 "." str2)
)
)
(t (setq str string_with_comma))
)
)
;;;=======================================
(defun MakeText (point string Height Ang justify Style Layer Color xdata / Lst)
; Ang: Radial
(setq Lst (list '(0 . "TEXT")
(cons 8 (if Layer Layer (getvar "Clayer")))
(cons 62 (if Color Color 256))
(cons 10 point)
(cons 40 Height)
(cons 1 string)
(if Ang (cons 50 Ang))
(cons 7 (if Style Style (getvar "Textstyle")))
(cons -3 (if xdata (list xdata) nil)))
justify (strcase justify))
(cond ((= justify "C") (setq Lst (append Lst (list (cons 72 1) (cons 11 point)))))
((= justify "R") (setq Lst (append Lst (list (cons 72 2) (cons 11 point)))))
((= justify "M") (setq Lst (append Lst (list (cons 72 4) (cons 11 point)))))
((= justify "TL") (setq Lst (append Lst (list (cons 72 0) (cons 11 point) (cons 73 3)))))
((= justify "TC") (setq Lst (append Lst (list (cons 72 1) (cons 11 point) (cons 73 3)))))
((= justify "TR") (setq Lst (append Lst (list (cons 72 2) (cons 11 point) (cons 73 3)))))
((= justify "ML") (setq Lst (append Lst (list (cons 72 0) (cons 11 point) (cons 73 2)))))
((= justify "MC") (setq Lst (append Lst (list (cons 72 1) (cons 11 point) (cons 73 2)))))
((= justify "MR") (setq Lst (append Lst (list (cons 72 2) (cons 11 point) (cons 73 2)))))
((= justify "BL") (setq Lst (append Lst (list (cons 72 0) (cons 11 point) (cons 73 1)))))
((= justify "BC") (setq Lst (append Lst (list (cons 72 1) (cons 11 point) (cons 73 1)))))
((= justify "BR") (setq Lst (append Lst (list (cons 72 2) (cons 11 point) (cons 73 1)))))
)
(entmakex Lst)
);endThảo luận gốc
Lisp được chia sẻ trong chủ đề Nội suy cao độ trên chiếu bằng. Xem đúng bài viết #424347 để đọc hướng dẫn và trao đổi thêm.