Jump to content

Lisp lệnh NS trong chủ đề “Nội suy cao độ trên chiếu bằng”

Đang rảnh, múc tới cho bạn 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)))
		)
	)
	(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))
)
)

 

Cách dùng

  1. Tải tệp 424320_ns.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 NS để chạy lisp.

Mã nguồn 424320_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)))
		)
	)
	(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))
)
)

Thả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 #424320 để đọc hướng dẫn và trao đổi thêm.

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