Chuyển đến nội dung
Diễn đàn CADViet
namgiangduy89

Nhờ Viết Lisp Tọa Độ Theo File Đính Kem

Các bài được khuyến nghị

Vấn đề hết sức đơn giản, do Bạn không chịu tìm hiểu và học hỏi

Cách đơn giản là bạn đổi file *.csv thành *.txt, lấy excel mở file *.txt rôid tungd bước làm như hình

3202_gif.gif

Chia sẻ bài đăng này


Liên kết tới bài đăng
Chia sẻ trên các trang web khác

Để phân cột file .csv, nó phụ thuộc vào Decimal symbol. Nghĩa là khi ô màu đỏ là dấu "." thì biến (setq sep ","), khi ô màu đỏ là dấu "," thì biến (setq sep ";")

tất nhiên ô màu xanh là ăn theo (nếu Decimal symbol là "." thì Digit grouping là "," là ngược lại)

Bạn Test thử Lisp của Lee khi thay đổi Decimal symbol để kiểm nghiệm trong trường hợp này thì có lẽ Lee đã nhầm lẫn :)


Test 10 trường hợp:

67029_csv.png

Chia sẻ bài đăng này


Liên kết tới bài đăng
Chia sẻ trên các trang web khác

Xem qua code thì thấy quá dài, muốn kiểm tra thì quá oải . Bài ở mục   #9

không biết bạn đã down về chưa mà cứ đòi Help hoài :) . Ở bài trướ đó thì

(initget "Cad Excel cadAndexcel")

(setq key (NGT key "Cad" getkword "Enter an option [Cad/Excel/cad_And_excel]"))

nên không nhận ra cadAndexcel thì đúng rồi. Nhưng bài ở mục 9 thì đã sửa :

(initget "Cad Excel cadAndexcel")

(setq key (NGT key "Cad" getkword "Enter an option [Cad/Excel/cadAndexcel]"))

Chắc down nhiều quá nên lẫn lộn chăng :D

ok, thanks bạn nhé

Chia sẻ bài đăng này


Liên kết tới bài đăng
Chia sẻ trên các trang web khác

Bác nào ghé qua hoàn chỉnh dùm lisp giống hình vẻ em với, Bổ sung dùm em câu lệnh "khi muốn lấy TD, chỉ cần vẽ Rectang ,pick một phát là nó  tự đánh số và xuất ra bảng toạ độ luôn.

Chia sẻ bài đăng này


Liên kết tới bài đăng
Chia sẻ trên các trang web khác

 

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))
)

mình mới tập tành ứng dụng lisp. tải file này về thực hành chạy cũng ổn. mình chỉ cần tính khoảng cách giữa 2 điểm nghĩa là chọn pick point 2 điểm là ngắt 1 khoảng cách rồi lặp lại 2 điểm khác chứ trong này nó chọn liên tiếp. rồi xuất ra 1 bản tính trên cad như file bạn làm này thôi còn mình tự copy sang excel. bạn xem chỗ nào đó sửa giúp dùm mình với.

Chia sẻ bài đăng này


Liên kết tới bài đăng
Chia sẻ trên các trang web khác

Chỉnh Excel thành cột dễ mà. Start-> Control panel->Clock, Language, and region->Change the date, time, or number format. Tại tab Format chọn English (United States) -> ok. 

Chia sẻ bài đăng này


Liên kết tới bài đăng
Chia sẻ trên các trang web khác

Tạo một tài khoản hoặc đăng nhập để nhận xét

Bạn cần phải là một thành viên để lại một bình luận

Tạo tài khoản

Đăng ký một tài khoản mới trong cộng đồng của chúng tôi. Điều đó dễ mà.

Đăng ký tài khoản mới

Đăng nhập

Bạn có sẵn sàng để tạo một tài khoản ? Đăng nhập tại đây.

Đăng nhập ngay

×