Lisp lệnh EC trong chủ đề “Nhờ Viết Lisp Tọa Độ Theo File Đính Kem”
Rảnh nên soạn sớ tấu cho bạn đây :D :D :D
(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/cadAndexcel]")) (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 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 ;================================= ;================================= (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)) )
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
- Chép mã nguồn, lưu thành tệp 386386_ec.lsp.
- 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 EC để chạy lisp.
Mã nguồn 386386_ec.lsp (trích từ bài viết gốc)
(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/cadAndexcel]"))
(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 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
;=================================
;=================================
(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))
)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 #386386 để đọc hướng dẫn và trao đổi thêm.