Jump to content

Lisp lệnh EC trong chủ đề “Nhờ Viết Lisp Tọa Độ Theo File Đính Kem”

Lỗi là do hàm MakeText chưa được load _ mình cũng không hiểu vì sao :D :D :D

 

>>> Xử lý: Bạn Cut đoạn code định nghĩa hàm MakeText >>> paste xuống cuối cùng nhé !

;; free lisp from cadviet.com
;;; this lisp was downloaded from https://www.cadviet.com/forum/topic/154743-nha-via-t-lisp-ta-a-a-theo-file-a-nh-kem/
(defun c:EC( / i p point lst key base_pnt last_pnt fn pw)
;Export Coordinates
(setq i 1)
(while (setq p (getpoint "\nPick Point: "))
	(setq point p)
	(MakeText (itoa i) 2.5 0 "L" nil nil 1 nil)
	(setq p (list i (car p) (cadr p))
	i (1+ i)
	lst (cons p lst)))
(if (> (length lst) 2)
	(progn
		(initget "Cad Excel cadAndexcel")
		(setq key (NGT key "Cad" getkword "Enter an option "))
		(cond
			((wcmatch key "Cad") 
				(setq #textheight (NGT #textheight 2 getint "Chieu cao chu"))
				(setq base_pnt (getpoint "\nDiem chen: "))
				(H:Creat_Cel+Data base_pnt 'L1 'L2 'L3 'L4 nil (* 5 #textheight) (* 0.5 #textheight) #textheight "MC" "STT" nil)
				(setq base_pnt (polar base_pnt 0 (* 5 #textheight)))
				(H:Creat_Cel+Data base_pnt 'L1 'L2 'L3 nil nil (* 15 #textheight) (* 0.5 #textheight) #textheight "MC" "X" nil)
				(setq base_pnt (polar base_pnt 0 (* 15 #textheight)))
				(H:Creat_Cel+Data base_pnt 'L1 'L2 'L3 nil nil (* 15 #textheight) (* 0.5 #textheight) #textheight "MC" "Y" nil)
				(setq base_pnt (polar base_pnt 0 (* 15 #textheight)))
				(H:Creat_Cel+Data base_pnt 'L1 'L2 'L3 nil nil (* 10 #textheight) (* 0.5 #textheight) #textheight "MC" "K/CACH (m)" nil)
			;;Xong tieu de
				(setq base_pnt (polar (polar base_pnt pi (* 35 #textheight)) (* 1.5 pi) (* 2 #textheight)))
				(H:Creat_Cel+Data base_pnt 'L1 'L2 nil 'L4 nil (* 5 #textheight) (* 0.5 #textheight) #textheight "MC" (itoa (car (last lst))) nil)
				(setq base_pnt (polar base_pnt 0 (* 5 #textheight)))
				(H:Creat_Cel+Data base_pnt 'L1 'L2 nil nil nil (* 15 #textheight) (* 0.5 #textheight) #textheight "MR" (rtos (cadr (last lst)) 2 3) nil)
				(setq base_pnt (polar base_pnt 0 (* 15 #textheight)))
				(H:Creat_Cel+Data base_pnt 'L1 'L2 nil nil nil (* 15 #textheight) (* 0.5 #textheight) #textheight "MR" (rtos (last (last lst)) 2 3) nil)
				(setq base_pnt (polar base_pnt 0 (* 15 #textheight)))
				(H:Creat_Cel+Data base_pnt nil 'L2 nil nil nil (* 10 #textheight) (* 0.5 #textheight) #textheight "MC" nil nil)
				(setq last_pnt (cdr (last lst)))
			;;Xong dong 1
				(foreach p (cdr (reverse lst))
					(setq base_pnt (polar (polar base_pnt pi (* 35 #textheight)) (* 1.5 pi) (* 2 #textheight)))
					(H:Creat_Cel+Data base_pnt 'L1 'L2 nil 'L4 nil (* 5 #textheight) (* 0.5 #textheight) #textheight "MC" (itoa (car p)) nil)
					(setq base_pnt (polar base_pnt 0 (* 5 #textheight)))
					(H:Creat_Cel+Data base_pnt 'L1 'L2 nil nil nil (* 15 #textheight) (* 0.5 #textheight) #textheight "MR" (rtos (cadr p) 2 3) nil)
					(setq base_pnt (polar base_pnt 0 (* 15 #textheight)))
					(H:Creat_Cel+Data base_pnt 'L1 'L2 nil nil nil (* 15 #textheight) (* 0.5 #textheight) #textheight "MR" (rtos (last p) 2 3) nil)
					(setq base_pnt (polar base_pnt 0 (* 15 #textheight)))
					(H:Creat_Cel+Data base_pnt nil 'L2 nil nil nil (* 10 #textheight) (* 0.5 #textheight) #textheight "M" (rtos (distance last_pnt (setq last_pnt (cdr p))) 2 3) nil)
				)
			;;Xong cac diem giua
				(setq base_pnt (polar (polar base_pnt pi (* 35 #textheight)) (* 1.5 pi) (* 2 #textheight)))
				(H:Creat_Cel+Data base_pnt 'L1 'L2 nil 'L4 nil (* 5 #textheight) (* 0.5 #textheight) #textheight "MC" (itoa (car (last lst))) nil)
				(setq base_pnt (polar base_pnt 0 (* 5 #textheight)))
				(H:Creat_Cel+Data base_pnt 'L1 'L2 nil nil nil (* 15 #textheight) (* 0.5 #textheight) #textheight "MR" (rtos (cadr (last lst)) 2 3) nil)
				(setq base_pnt (polar base_pnt 0 (* 15 #textheight)))
				(H:Creat_Cel+Data base_pnt 'L1 'L2 nil nil nil (* 15 #textheight) (* 0.5 #textheight) #textheight "MR" (rtos (last (last lst)) 2 3) nil)
				(setq base_pnt (polar base_pnt 0 (* 15 #textheight)))
				(H:Creat_Cel+Data base_pnt 'L1 'L2 nil nil nil (* 10 #textheight) (* 0.5 #textheight) #textheight "M" (rtos (distance last_pnt (cdr (last lst))) 2 3) nil)
			;;Xong lap lai dong 1 + k/cach khep
			)
			((wcmatch key "Excel")
				(setq fn (getfiled "Chon file de xuat ket qua" "" "csv" 1))
 				(setq pw (open fn "w"))
				(write-line "STT,X,Y,K/cach (m)" pw)
				(write-line (strcat (itoa (car (last lst))) "," (rtos (cadr (last lst)) 2 3) "," (rtos (last (last lst)) 2 3)) pw)
				(setq last_pnt (cdr (last lst)))
 				(foreach p (cdr (reverse lst))
  				(write-line (strcat (itoa (car p)) "," (rtos (cadr p) 2 3) "," (rtos (last p) 2 3) "," (rtos (distance last_pnt (setq last_pnt (cdr p))) 2 3)) pw)
				)
				(write-line (strcat (itoa (car (last lst))) "," (rtos (cadr (last lst)) 2 3) "," (rtos (last (last lst)) 2 3) "," (rtos (distance last_pnt (cdr (last lst))) 2 3)) pw)
 				(close pw)
			)
			(t
				(setq #textheight (NGT #textheight 2 getint "Chieu cao chu"))
				(setq base_pnt (getpoint "\nDiem chen: "))
				(H:Creat_Cel+Data base_pnt 'L1 'L2 'L3 'L4 nil (* 5 #textheight) (* 0.5 #textheight) #textheight "MC" "STT" nil)
				(setq base_pnt (polar base_pnt 0 (* 5 #textheight)))
				(H:Creat_Cel+Data base_pnt 'L1 'L2 'L3 nil nil (* 15 #textheight) (* 0.5 #textheight) #textheight "MC" "X" nil)
				(setq base_pnt (polar base_pnt 0 (* 15 #textheight)))
				(H:Creat_Cel+Data base_pnt 'L1 'L2 'L3 nil nil (* 15 #textheight) (* 0.5 #textheight) #textheight "MC" "Y" nil)
				(setq base_pnt (polar base_pnt 0 (* 15 #textheight)))
				(H:Creat_Cel+Data base_pnt 'L1 'L2 'L3 nil nil (* 10 #textheight) (* 0.5 #textheight) #textheight "MC" "K/CACH (m)" nil)
			;;Xong tieu de
				(setq base_pnt (polar (polar base_pnt pi (* 35 #textheight)) (* 1.5 pi) (* 2 #textheight)))
				(H:Creat_Cel+Data base_pnt 'L1 'L2 nil 'L4 nil (* 5 #textheight) (* 0.5 #textheight) #textheight "MC" (itoa (car (last lst))) nil)
				(setq base_pnt (polar base_pnt 0 (* 5 #textheight)))
				(H:Creat_Cel+Data base_pnt 'L1 'L2 nil nil nil (* 15 #textheight) (* 0.5 #textheight) #textheight "MR" (rtos (cadr (last lst)) 2 3) nil)
				(setq base_pnt (polar base_pnt 0 (* 15 #textheight)))
				(H:Creat_Cel+Data base_pnt 'L1 'L2 nil nil nil (* 15 #textheight) (* 0.5 #textheight) #textheight "MR" (rtos (last (last lst)) 2 3) nil)
				(setq base_pnt (polar base_pnt 0 (* 15 #textheight)))
				(H:Creat_Cel+Data base_pnt nil 'L2 nil nil nil (* 10 #textheight) (* 0.5 #textheight) #textheight "MC" nil nil)
				(setq last_pnt (cdr (last lst)))
			;;Xong dong 1
				(foreach p (cdr (reverse lst))
					(setq base_pnt (polar (polar base_pnt pi (* 35 #textheight)) (* 1.5 pi) (* 2 #textheight)))
					(H:Creat_Cel+Data base_pnt 'L1 'L2 nil 'L4 nil (* 5 #textheight) (* 0.5 #textheight) #textheight "MC" (itoa (car p)) nil)
					(setq base_pnt (polar base_pnt 0 (* 5 #textheight)))
					(H:Creat_Cel+Data base_pnt 'L1 'L2 nil nil nil (* 15 #textheight) (* 0.5 #textheight) #textheight "MR" (rtos (cadr p) 2 3) nil)
					(setq base_pnt (polar base_pnt 0 (* 15 #textheight)))
					(H:Creat_Cel+Data base_pnt 'L1 'L2 nil nil nil (* 15 #textheight) (* 0.5 #textheight) #textheight "MR" (rtos (last p) 2 3) nil)
					(setq base_pnt (polar base_pnt 0 (* 15 #textheight)))
					(H:Creat_Cel+Data base_pnt nil 'L2 nil nil nil (* 10 #textheight) (* 0.5 #textheight) #textheight "M" (rtos (distance last_pnt (setq last_pnt (cdr p))) 2 3) nil)
				)
			;;Xong cac diem giua
				(setq base_pnt (polar (polar base_pnt pi (* 35 #textheight)) (* 1.5 pi) (* 2 #textheight)))
				(H:Creat_Cel+Data base_pnt 'L1 'L2 nil 'L4 nil (* 5 #textheight) (* 0.5 #textheight) #textheight "MC" (itoa (car (last lst))) nil)
				(setq base_pnt (polar base_pnt 0 (* 5 #textheight)))
				(H:Creat_Cel+Data base_pnt 'L1 'L2 nil nil nil (* 15 #textheight) (* 0.5 #textheight) #textheight "MR" (rtos (cadr (last lst)) 2 3) nil)
				(setq base_pnt (polar base_pnt 0 (* 15 #textheight)))
				(H:Creat_Cel+Data base_pnt 'L1 'L2 nil nil nil (* 15 #textheight) (* 0.5 #textheight) #textheight "MR" (rtos (last (last lst)) 2 3) nil)
				(setq base_pnt (polar base_pnt 0 (* 15 #textheight)))
				(H:Creat_Cel+Data base_pnt 'L1 'L2 nil nil nil (* 10 #textheight) (* 0.5 #textheight) #textheight "M" (rtos (distance last_pnt (cdr (last lst))) 2 3) nil)
			;;Xong lap lai dong 1 + k/cach khep
			;;Xong chen bang trong cad
				(setq fn (getfiled "Chon file de xuat ket qua" "" "csv" 1))
 				(setq pw (open fn "w"))
				(write-line "STT,X,Y,K/cach (m)" pw)
				(write-line (strcat (itoa (car (last lst))) "," (rtos (cadr (last lst)) 2 3) "," (rtos (last (last lst)) 2 3)) pw)
				(setq last_pnt (cdr (last lst)))
 				(foreach p (cdr (reverse lst))
  				(write-line (strcat (itoa (car p)) "," (rtos (cadr p) 2 3) "," (rtos (last p) 2 3) "," (rtos (distance last_pnt (setq last_pnt (cdr p))) 2 3)) pw)
				)
				(write-line (strcat (itoa (car (last lst))) "," (rtos (cadr (last lst)) 2 3) "," (rtos (last (last lst)) 2 3) "," (rtos (distance last_pnt (cdr (last lst))) 2 3)) pw)
 				(close pw)
			)
		)
	)
	(princ "\n***** Phai pick >2 diem ! ***")
)
(princ)
)
;;;End main
;===============================================================================================
(defun NGT(a mac_dinh ham str_nhac / modul)
;;Nhan gia tri
(or a (setq a mac_dinh))
(setq a (cond
	((= "" (setq modul (ham (strcat "\n" str_nhac " <" (vl-princ-to-string a) ">: ")))) a)
	(modul)
	(a)
	)
	)
)
;=====================
(defun H:Creat_Cel+Data (base_pnt L1 L2 L3 L4 celheight celwidth offset textheight justify string Ang / pnt2 pnt3 pnt4 justify point)

;=================================
(defun MakeLine (PT1 PT2 Linetype LTScale Layer Color xdata)	
(entmakex (list '(0 . "LINE")									
				(cons 8 (if Layer Layer (getvar "Clayer")))								  
				(cons 6 (if Linetype Linetype "bylayer"))								  
				(cons 48 (if LTScale LTScale 1))									
				(cons 62 (if Color Color 256))									
				(cons 10 PT1)	(cons 11 PT2)									
				(cons -3 (if xdata (list xdata) nil))))
);end
;=================================
(if (null celheight) (setq celheight (+ textheight (* 2 offset))))
(setq	pnt2 (polar base_pnt 0 celwidth)
		pnt3 (polar pnt2 (* 1.5 pi) celheight)
		pnt4 (polar pnt3 pi celwidth)
		)
(if justify (setq justify (strcase justify)))
(cond
	((wcmatch justify "C,BC") (setq point (polar (polar pnt4 (* 0.5 pi) offset) 0 (* 0.5 celwidth))))
	((wcmatch justify "R,BR") (setq point (polar pnt3 (* 0.75 pi) (* offset (sqrt 2)))))
	((wcmatch justify "M") (setq point (polar base_pnt 0 (* 0.5 celwidth))))
	((wcmatch justify "MC") (setq point (polar (polar pnt4 (* 0.5 pi) (* 0.5 celheight)) 0 (* 0.5 celwidth))))
	((wcmatch justify "TL")	(setq point (polar (polar base_pnt (* 1.5 pi) offset) 0 offset)))
	((wcmatch justify "TC")	(setq point (polar (polar base_pnt (* 1.5 pi) offset) 0 (* 0.5 celheight))))
	((wcmatch justify "TR")	(setq point (polar pnt2 (* 1.25 pi) (* offset (sqrt 2)))))
	((wcmatch justify "ML")	(setq point (polar (polar base_pnt (* 1.5 pi) (* 0.5 celheight)) 0 offset)))
	((wcmatch justify "MR")	(setq point (polar (polar pnt2 (* 1.5 pi) (* 0.5 celheight)) pi offset)))
	(t (setq point (polar pnt4 (* 0.25 pi) (* offset (sqrt 2)))))
)
(if L1 (MakeLine pnt4 pnt3 nil nil nil nil nil))
(if L2 (MakeLine pnt3 pnt2 nil nil nil nil nil))
(if L3 (MakeLine base_pnt pnt2 nil nil nil nil nil))
(if L4 (MakeLine pnt4 base_pnt nil nil nil nil nil))
(if string (MakeText string textheight Ang justify nil nil nil nil))
)
;===================================
(defun MakeText (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)									
				(cons 50 (if Ang Ang 0))									
				(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
;=================================

p/s: Tiện thể, có bác nào ngang qua cho em hỏi: Vì sao khi "bỏ" hàm MakeText vào trong hàm H:Creat_Cel+Data (mục đích để định nghĩa lại nó mỗi khi gọi hàm H:Creat_Cel+Data tránh sai sót) và đã không thiết lập nó là biến cục bộ thì cad không load được hàm MakeText.

Phải chăng là do mình đã để ngõ tham số point trong đó.

Cảm ơn bác hiepttr nhiều cơ bản lisp đã gần đúng ý em, em đã text và nhờ bác chỉnh lại cho em tí.

1. Khoảng cách các cột Tọa độ X,Y , K/CÁCH hơi rộng

2. Các Text chưa được canh giữa.

3. Phần câu lệnh xuất bảng kết quả sang Cad thì đã Ok, còn xuất sang Excel em đã làm nhưng xuất sang excel nhìn rất rối( các số gộp lại chung một cột) bác có cách nào khắc phục không, nếu không bác chuyển qua định dạng TXT luôn để e chuyển vào máy toàn đạt cắm mốc luôn.

4. Câu lênh xuất kết quả trên Cad và excel thì chỉ thấy kết quả trên cad còn trên Excel không thấy dấu hiệu gì.

Tiện thể mình gỡi Bác File cad mình bố trí bảng kết quả để bác chỉnh lại kích thước cho phù hợp 

https://www.cadviet.com/upfiles/5/133575_b2_03.dwg

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 386549_ec.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 EC để chạy lisp.

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

;; free lisp from cadviet.com
;;; this lisp was downloaded from https://www.cadviet.com/forum/topic/154743-nha-via-t-lisp-ta-a-a-theo-file-a-nh-kem/
(defun c:EC( / i p point lst key base_pnt last_pnt fn pw)
;Export Coordinates
(setq i 1)
(while (setq p (getpoint "\nPick Point: "))
	(setq point p)
	(MakeText (itoa i) 2.5 0 "L" nil nil 1 nil)
	(setq p (list i (car p) (cadr p))
	i (1+ i)
	lst (cons p lst)))
(if (> (length lst) 2)
	(progn
		(initget "Cad Excel cadAndexcel")
		(setq key (NGT key "Cad" getkword "Enter an option [Cad/Excel/cad_And_excel]"))
		(cond
			((wcmatch key "Cad") 
				(setq #textheight (NGT #textheight 2 getint "Chieu cao chu"))
				(setq base_pnt (getpoint "\nDiem chen: "))
				(H:Creat_Cel+Data base_pnt 'L1 'L2 'L3 'L4 nil (* 5 #textheight) (* 0.5 #textheight) #textheight "MC" "STT" nil)
				(setq base_pnt (polar base_pnt 0 (* 5 #textheight)))
				(H:Creat_Cel+Data base_pnt 'L1 'L2 'L3 nil nil (* 15 #textheight) (* 0.5 #textheight) #textheight "MC" "X" nil)
				(setq base_pnt (polar base_pnt 0 (* 15 #textheight)))
				(H:Creat_Cel+Data base_pnt 'L1 'L2 'L3 nil nil (* 15 #textheight) (* 0.5 #textheight) #textheight "MC" "Y" nil)
				(setq base_pnt (polar base_pnt 0 (* 15 #textheight)))
				(H:Creat_Cel+Data base_pnt 'L1 'L2 'L3 nil nil (* 10 #textheight) (* 0.5 #textheight) #textheight "MC" "K/CACH (m)" nil)
			;;Xong tieu de
				(setq base_pnt (polar (polar base_pnt pi (* 35 #textheight)) (* 1.5 pi) (* 2 #textheight)))
				(H:Creat_Cel+Data base_pnt 'L1 'L2 nil 'L4 nil (* 5 #textheight) (* 0.5 #textheight) #textheight "MC" (itoa (car (last lst))) nil)
				(setq base_pnt (polar base_pnt 0 (* 5 #textheight)))
				(H:Creat_Cel+Data base_pnt 'L1 'L2 nil nil nil (* 15 #textheight) (* 0.5 #textheight) #textheight "MR" (rtos (cadr (last lst)) 2 3) nil)
				(setq base_pnt (polar base_pnt 0 (* 15 #textheight)))
				(H:Creat_Cel+Data base_pnt 'L1 'L2 nil nil nil (* 15 #textheight) (* 0.5 #textheight) #textheight "MR" (rtos (last (last lst)) 2 3) nil)
				(setq base_pnt (polar base_pnt 0 (* 15 #textheight)))
				(H:Creat_Cel+Data base_pnt nil 'L2 nil nil nil (* 10 #textheight) (* 0.5 #textheight) #textheight "MC" nil nil)
				(setq last_pnt (cdr (last lst)))
			;;Xong dong 1
				(foreach p (cdr (reverse lst))
					(setq base_pnt (polar (polar base_pnt pi (* 35 #textheight)) (* 1.5 pi) (* 2 #textheight)))
					(H:Creat_Cel+Data base_pnt 'L1 'L2 nil 'L4 nil (* 5 #textheight) (* 0.5 #textheight) #textheight "MC" (itoa (car p)) nil)
					(setq base_pnt (polar base_pnt 0 (* 5 #textheight)))
					(H:Creat_Cel+Data base_pnt 'L1 'L2 nil nil nil (* 15 #textheight) (* 0.5 #textheight) #textheight "MR" (rtos (cadr p) 2 3) nil)
					(setq base_pnt (polar base_pnt 0 (* 15 #textheight)))
					(H:Creat_Cel+Data base_pnt 'L1 'L2 nil nil nil (* 15 #textheight) (* 0.5 #textheight) #textheight "MR" (rtos (last p) 2 3) nil)
					(setq base_pnt (polar base_pnt 0 (* 15 #textheight)))
					(H:Creat_Cel+Data base_pnt nil 'L2 nil nil nil (* 10 #textheight) (* 0.5 #textheight) #textheight "M" (rtos (distance last_pnt (setq last_pnt (cdr p))) 2 3) nil)
				)
			;;Xong cac diem giua
				(setq base_pnt (polar (polar base_pnt pi (* 35 #textheight)) (* 1.5 pi) (* 2 #textheight)))
				(H:Creat_Cel+Data base_pnt 'L1 'L2 nil 'L4 nil (* 5 #textheight) (* 0.5 #textheight) #textheight "MC" (itoa (car (last lst))) nil)
				(setq base_pnt (polar base_pnt 0 (* 5 #textheight)))
				(H:Creat_Cel+Data base_pnt 'L1 'L2 nil nil nil (* 15 #textheight) (* 0.5 #textheight) #textheight "MR" (rtos (cadr (last lst)) 2 3) nil)
				(setq base_pnt (polar base_pnt 0 (* 15 #textheight)))
				(H:Creat_Cel+Data base_pnt 'L1 'L2 nil nil nil (* 15 #textheight) (* 0.5 #textheight) #textheight "MR" (rtos (last (last lst)) 2 3) nil)
				(setq base_pnt (polar base_pnt 0 (* 15 #textheight)))
				(H:Creat_Cel+Data base_pnt 'L1 'L2 nil nil nil (* 10 #textheight) (* 0.5 #textheight) #textheight "M" (rtos (distance last_pnt (cdr (last lst))) 2 3) nil)
			;;Xong lap lai dong 1 + k/cach khep
			)
			((wcmatch key "Excel")
				(setq fn (getfiled "Chon file de xuat ket qua" "" "csv" 1))
 				(setq pw (open fn "w"))
				(write-line "STT,X,Y,K/cach (m)" pw)
				(write-line (strcat (itoa (car (last lst))) "," (rtos (cadr (last lst)) 2 3) "," (rtos (last (last lst)) 2 3)) pw)
				(setq last_pnt (cdr (last lst)))
 				(foreach p (cdr (reverse lst))
  				(write-line (strcat (itoa (car p)) "," (rtos (cadr p) 2 3) "," (rtos (last p) 2 3) "," (rtos (distance last_pnt (setq last_pnt (cdr p))) 2 3)) pw)
				)
				(write-line (strcat (itoa (car (last lst))) "," (rtos (cadr (last lst)) 2 3) "," (rtos (last (last lst)) 2 3) "," (rtos (distance last_pnt (cdr (last lst))) 2 3)) pw)
 				(close pw)
			)
			(t
				(setq #textheight (NGT #textheight 2 getint "Chieu cao chu"))
				(setq base_pnt (getpoint "\nDiem chen: "))
				(H:Creat_Cel+Data base_pnt 'L1 'L2 'L3 'L4 nil (* 5 #textheight) (* 0.5 #textheight) #textheight "MC" "STT" nil)
				(setq base_pnt (polar base_pnt 0 (* 5 #textheight)))
				(H:Creat_Cel+Data base_pnt 'L1 'L2 'L3 nil nil (* 15 #textheight) (* 0.5 #textheight) #textheight "MC" "X" nil)
				(setq base_pnt (polar base_pnt 0 (* 15 #textheight)))
				(H:Creat_Cel+Data base_pnt 'L1 'L2 'L3 nil nil (* 15 #textheight) (* 0.5 #textheight) #textheight "MC" "Y" nil)
				(setq base_pnt (polar base_pnt 0 (* 15 #textheight)))
				(H:Creat_Cel+Data base_pnt 'L1 'L2 'L3 nil nil (* 10 #textheight) (* 0.5 #textheight) #textheight "MC" "K/CACH (m)" nil)
			;;Xong tieu de
				(setq base_pnt (polar (polar base_pnt pi (* 35 #textheight)) (* 1.5 pi) (* 2 #textheight)))
				(H:Creat_Cel+Data base_pnt 'L1 'L2 nil 'L4 nil (* 5 #textheight) (* 0.5 #textheight) #textheight "MC" (itoa (car (last lst))) nil)
				(setq base_pnt (polar base_pnt 0 (* 5 #textheight)))
				(H:Creat_Cel+Data base_pnt 'L1 'L2 nil nil nil (* 15 #textheight) (* 0.5 #textheight) #textheight "MR" (rtos (cadr (last lst)) 2 3) nil)
				(setq base_pnt (polar base_pnt 0 (* 15 #textheight)))
				(H:Creat_Cel+Data base_pnt 'L1 'L2 nil nil nil (* 15 #textheight) (* 0.5 #textheight) #textheight "MR" (rtos (last (last lst)) 2 3) nil)
				(setq base_pnt (polar base_pnt 0 (* 15 #textheight)))
				(H:Creat_Cel+Data base_pnt nil 'L2 nil nil nil (* 10 #textheight) (* 0.5 #textheight) #textheight "MC" nil nil)
				(setq last_pnt (cdr (last lst)))
			;;Xong dong 1
				(foreach p (cdr (reverse lst))
					(setq base_pnt (polar (polar base_pnt pi (* 35 #textheight)) (* 1.5 pi) (* 2 #textheight)))
					(H:Creat_Cel+Data base_pnt 'L1 'L2 nil 'L4 nil (* 5 #textheight) (* 0.5 #textheight) #textheight "MC" (itoa (car p)) nil)
					(setq base_pnt (polar base_pnt 0 (* 5 #textheight)))
					(H:Creat_Cel+Data base_pnt 'L1 'L2 nil nil nil (* 15 #textheight) (* 0.5 #textheight) #textheight "MR" (rtos (cadr p) 2 3) nil)
					(setq base_pnt (polar base_pnt 0 (* 15 #textheight)))
					(H:Creat_Cel+Data base_pnt 'L1 'L2 nil nil nil (* 15 #textheight) (* 0.5 #textheight) #textheight "MR" (rtos (last p) 2 3) nil)
					(setq base_pnt (polar base_pnt 0 (* 15 #textheight)))
					(H:Creat_Cel+Data base_pnt nil 'L2 nil nil nil (* 10 #textheight) (* 0.5 #textheight) #textheight "M" (rtos (distance last_pnt (setq last_pnt (cdr p))) 2 3) nil)
				)
			;;Xong cac diem giua
				(setq base_pnt (polar (polar base_pnt pi (* 35 #textheight)) (* 1.5 pi) (* 2 #textheight)))
				(H:Creat_Cel+Data base_pnt 'L1 'L2 nil 'L4 nil (* 5 #textheight) (* 0.5 #textheight) #textheight "MC" (itoa (car (last lst))) nil)
				(setq base_pnt (polar base_pnt 0 (* 5 #textheight)))
				(H:Creat_Cel+Data base_pnt 'L1 'L2 nil nil nil (* 15 #textheight) (* 0.5 #textheight) #textheight "MR" (rtos (cadr (last lst)) 2 3) nil)
				(setq base_pnt (polar base_pnt 0 (* 15 #textheight)))
				(H:Creat_Cel+Data base_pnt 'L1 'L2 nil nil nil (* 15 #textheight) (* 0.5 #textheight) #textheight "MR" (rtos (last (last lst)) 2 3) nil)
				(setq base_pnt (polar base_pnt 0 (* 15 #textheight)))
				(H:Creat_Cel+Data base_pnt 'L1 'L2 nil nil nil (* 10 #textheight) (* 0.5 #textheight) #textheight "M" (rtos (distance last_pnt (cdr (last lst))) 2 3) nil)
			;;Xong lap lai dong 1 + k/cach khep
			;;Xong chen bang trong cad
				(setq fn (getfiled "Chon file de xuat ket qua" "" "csv" 1))
 				(setq pw (open fn "w"))
				(write-line "STT,X,Y,K/cach (m)" pw)
				(write-line (strcat (itoa (car (last lst))) "," (rtos (cadr (last lst)) 2 3) "," (rtos (last (last lst)) 2 3)) pw)
				(setq last_pnt (cdr (last lst)))
 				(foreach p (cdr (reverse lst))
  				(write-line (strcat (itoa (car p)) "," (rtos (cadr p) 2 3) "," (rtos (last p) 2 3) "," (rtos (distance last_pnt (setq last_pnt (cdr p))) 2 3)) pw)
				)
				(write-line (strcat (itoa (car (last lst))) "," (rtos (cadr (last lst)) 2 3) "," (rtos (last (last lst)) 2 3) "," (rtos (distance last_pnt (cdr (last lst))) 2 3)) pw)
 				(close pw)
			)
		)
	)
	(princ "\n***** Phai pick >2 diem ! ***")
)
(princ)
)
;;;End main
;===============================================================================================
(defun NGT(a mac_dinh ham str_nhac / modul)
;;Nhan gia tri
(or a (setq a mac_dinh))
(setq a (cond
	((= "" (setq modul (ham (strcat "\n" str_nhac " <" (vl-princ-to-string a) ">: ")))) a)
	(modul)
	(a)
	)
	)
)
;=====================
(defun H:Creat_Cel+Data (base_pnt L1 L2 L3 L4 celheight celwidth offset textheight justify string Ang / pnt2 pnt3 pnt4 justify point)

;=================================
(defun MakeLine (PT1 PT2 Linetype LTScale Layer Color xdata)	
(entmakex (list '(0 . "LINE")									
				(cons 8 (if Layer Layer (getvar "Clayer")))								  
				(cons 6 (if Linetype Linetype "bylayer"))								  
				(cons 48 (if LTScale LTScale 1))									
				(cons 62 (if Color Color 256))									
				(cons 10 PT1)	(cons 11 PT2)									
				(cons -3 (if xdata (list xdata) nil))))
);end
;=================================
(if (null celheight) (setq celheight (+ textheight (* 2 offset))))
(setq	pnt2 (polar base_pnt 0 celwidth)
		pnt3 (polar pnt2 (* 1.5 pi) celheight)
		pnt4 (polar pnt3 pi celwidth)
		)
(if justify (setq justify (strcase justify)))
(cond
	((wcmatch justify "C,BC") (setq point (polar (polar pnt4 (* 0.5 pi) offset) 0 (* 0.5 celwidth))))
	((wcmatch justify "R,BR") (setq point (polar pnt3 (* 0.75 pi) (* offset (sqrt 2)))))
	((wcmatch justify "M") (setq point (polar base_pnt 0 (* 0.5 celwidth))))
	((wcmatch justify "MC") (setq point (polar (polar pnt4 (* 0.5 pi) (* 0.5 celheight)) 0 (* 0.5 celwidth))))
	((wcmatch justify "TL")	(setq point (polar (polar base_pnt (* 1.5 pi) offset) 0 offset)))
	((wcmatch justify "TC")	(setq point (polar (polar base_pnt (* 1.5 pi) offset) 0 (* 0.5 celheight))))
	((wcmatch justify "TR")	(setq point (polar pnt2 (* 1.25 pi) (* offset (sqrt 2)))))
	((wcmatch justify "ML")	(setq point (polar (polar base_pnt (* 1.5 pi) (* 0.5 celheight)) 0 offset)))
	((wcmatch justify "MR")	(setq point (polar (polar pnt2 (* 1.5 pi) (* 0.5 celheight)) pi offset)))
	(t (setq point (polar pnt4 (* 0.25 pi) (* offset (sqrt 2)))))
)
(if L1 (MakeLine pnt4 pnt3 nil nil nil nil nil))
(if L2 (MakeLine pnt3 pnt2 nil nil nil nil nil))
(if L3 (MakeLine base_pnt pnt2 nil nil nil nil nil))
(if L4 (MakeLine pnt4 base_pnt nil nil nil nil nil))
(if string (MakeText string textheight Ang justify nil nil nil nil))
)
;===================================
(defun MakeText (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)									
				(cons 50 (if Ang Ang 0))									
				(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
;=================================

Thảo luận gốc

Lisp được chia sẻ trong chủ đề Nhờ Viết Lisp Tọa Độ Theo File Đính Kem. Xem đúng bài viết #386549 để đọc hướng dẫn và trao đổi thêm.

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