Jump to content

lisp Phun tọa độ các điểm từ file txt vào CAD

 

Có bác nào giúp em chỉnh sửa lisp của bác Gia_Bach http://www.cadviet.c.../80142_rft2.lsp

;; free lisp from cadviet.com
(defun c:RFT(/ data f h line pt pXY spc str ten val);Read File Txt
  ;|  By : Gia Bach, gia_bach @  www.CadViet.com 			|;  
  (vl-load-com)
  (defun Split (Str Char / Lst pos)
	(while (setq pos (vl-string-search Char Str))
  	(if (null Lst)
(setq Lst (list (substr Str 1 pos)))
(setq Lst (append Lst (list (read (substr Str 1 pos))))))
  	(setq Str (substr Str (+ pos 2)) ))
	(setq Lst (append Lst (list (read Str)))))
 
  (if (setq ten (getfiled "Chon File txt" (getvar "dwgprefix") "txt" 8))
	(progn
  	(or (tblsearch "layer" "Point") (command "-layer" "n" "Point" "") )
  	(or (tblsearch "layer" "Sothutu") (command "-layer" "n" "Sothutu" "c" 3 "Sothutu" "") )
  	(or (tblsearch "layer" "Caodo") (command "-layer" "n" "Caodo" "c" 4 "Caodo" "") )
  	(setq spc (vla-get-ModelSpace (vla-get-ActiveDocument(vlax-get-Acad-Object))))
  	(setq h 2);(* (getvar "dimtxt")(getvar "dimscale")))
  	(setq f (open (findfile ten) "r"))
  	(while (setq Line (read-line f))
(if (vl-string-search "\t" Line)
   (progn
	(setq data (split Line "\t" )
	val (car data)
	pt  (cdr data))
	(if (not(vl-catch-all-error-p (vl-catch-all-apply 'vlax-3d-point pt)))
   	(progn
  (setq pXY (list (car pt)(cadr pt)))
  (vla-put-Layer (vla-addpoint spc (vlax-3d-point pXY)) "Point")
  (vla-put-Layer (setq str (vla-addtext spc val (vlax-3d-point pXY) h)) "Sothutu")
  (vla-put-Alignment str 8)
  (vla-put-TextAlignmentPoint str (vlax-3d-point pXY))
  (vla-put-Layer (vla-addtext spc (caddr pt) (vlax-3d-point pXY) h) "Caodo") )))))  ))
  (princ))
với yêu cầu:

- File text dạng : SST,Y,X,Z,Code

- Độ cao Z có dấu chấm ở hàng thập phân nằm đúng vào vị trí tọa độ (X,Y) của điểm đó .

Em xin cảm ơn trước.

Bạn ơi bạn có thể sửa để chạy ra

1. Layer: point

2. Layer: docao

3. Layer: madiem

4. Layer Tendiem

với số liệu thứ tự:

1.Tendiem          2. Tọa dộ X        3. Tọa dộ Y        4. Độ cao  H     5. Mã điểm

I-1_A=              2482493.792       417021.870         167.751            II-1

I-1_A=    2482493.792    417021.875    167.748    II-1

I-1_2    2482454.002    416964.167    175.394    ?

I-1_3    2482449.684    416963.618    173.798    ?

I-1_4    2482447.597    416959.881    175.082    ?

I-1_5    2482380.325    416886.284    167.977    S

I-1_6    2482360.346    416888.805    168.130    S

I-1_7    2482367.507    416866.060    169.516    Shttps://www.cadviet.com/upfiles/3/123341_a_1.rar

Cách dùng

  1. Tải tệp 257335_rft.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 RFT để chạy lisp.

Mã nguồn 257335_rft.lsp

;; free lisp from cadviet.com
;;; this lisp was downloaded from https://www.cadviet.com/forum/topic/20044-y%C3%AAu-c%E1%BA%A7u-lisp-phun-t%E1%BB%8Da-%C4%91%E1%BB%99-c%C3%A1c-%C4%91i%E1%BB%83m-t%E1%BB%AB-file-txt-v%C3%A0o-cad/?page=4&tab=comments
;; free lisp from cadviet.com
(defun c:RFT(/ data f h line pt pXY spc str ten val);Read File Txt
  ;|  By : Gia Bach, gia_bach @  www.CadViet.com 			|;  
  (vl-load-com)
  (defun Split (Str Char / Lst pos)
	(while (setq pos (vl-string-search Char Str))
  	(if (null Lst)
(setq Lst (list (substr Str 1 pos)))
(setq Lst (append Lst (list (read (substr Str 1 pos))))))
  	(setq Str (substr Str (+ pos 2)) ))
	(setq Lst (append Lst (list (read Str)))))
 
  (if (setq ten (getfiled "Chon File txt" (getvar "dwgprefix") "txt" 8))
	(progn
  	(or (tblsearch "layer" "Point") (command "-layer" "n" "Point" "") )
  	(or (tblsearch "layer" "Sothutu") (command "-layer" "n" "Sothutu" "c" 3 "Sothutu" "") )
  	(or (tblsearch "layer" "Caodo") (command "-layer" "n" "Caodo" "c" 4 "Caodo" "") )
  	(setq spc (vla-get-ModelSpace (vla-get-ActiveDocument(vlax-get-Acad-Object))))
  	(setq h 2);(* (getvar "dimtxt")(getvar "dimscale")))
  	(setq f (open (findfile ten) "r"))
  	(while (setq Line (read-line f))
(if (vl-string-search "\t" Line)
   (progn
	(setq data (split Line "\t" )
	val (car data)
	pt  (cdr data))
	(if (not(vl-catch-all-error-p (vl-catch-all-apply 'vlax-3d-point pt)))
   	(progn
  (setq pXY (list (car pt)(cadr pt)))
  (vla-put-Layer (vla-addpoint spc (vlax-3d-point pXY)) "Point")
  (vla-put-Layer (setq str (vla-addtext spc val (vlax-3d-point pXY) h)) "Sothutu")
  (vla-put-Alignment str 8)
  (vla-put-TextAlignmentPoint str (vlax-3d-point pXY))
  (vla-put-Layer (vla-addtext spc (caddr pt) (vlax-3d-point pXY) h) "Caodo") )))))  ))
  (princ))

Thảo luận gốc

Lisp được chia sẻ trong chủ đề [Yêu cầu] lisp Phun tọa độ các điểm từ file txt vào CAD. Xem đúng bài viết #257335 để đọc hướng dẫn và trao đổi thêm.

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